ble

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected     = errors.New("not connected to device")
	ErrNoDevice         = errors.New("no device found")
	ErrTimeout          = errors.New("operation timeout")
	ErrNoService        = errors.New("service not found")
	ErrNoCharacteristic = errors.New("characteristic not found")
	ErrFrameTooLarge    = errors.New("frame exceeds device buffer")
)
View Source
var (
	// ServiceUUID is the primary BLE service UUID for battery communication
	ServiceUUID = bluetooth.NewUUID([16]byte{
		0x00, 0x00, 0x10, 0x06, 0x00, 0x00, 0x10, 0x00,
		0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
	}) // 00001006-0000-1000-8000-00805f9b34fb

	// WriteCharacteristicUUID is the characteristic for writing commands to the battery
	WriteCharacteristicUUID = bluetooth.NewUUID([16]byte{
		0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x10, 0x00,
		0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
	}) // 00001008-0000-1000-8000-00805f9b34fb

	// NotifyCharacteristicUUID is the characteristic for receiving notifications from the battery
	NotifyCharacteristicUUID = bluetooth.NewUUID([16]byte{
		0x00, 0x00, 0x10, 0x07, 0x00, 0x00, 0x10, 0x00,
		0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
	}) // 00001007-0000-1000-8000-00805f9b34fb

	// CCCDescriptorUUID is the Client Characteristic Configuration descriptor
	CCCDescriptorUUID = bluetooth.NewUUID([16]byte{
		0x00, 0x00, 0x29, 0x02, 0x00, 0x00, 0x10, 0x00,
		0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb,
	}) // 00002902-0000-1000-8000-00805f9b34fb
)

UUIDs for Voltgo BLE protocol (compatible with Enerwatt, TCED Worldwide, and other brands)

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection represents a BLE connection to a battery

func NewConnection

func NewConnection() (*Connection, error)

NewConnection creates a new BLE connection handler

func (*Connection) Connect

func (c *Connection) Connect(_ context.Context, address bluetooth.Address) error

Connect connects to a BLE device by address and prepares the battery's write and notify characteristics.

func (*Connection) Disconnect

func (c *Connection) Disconnect() error

Disconnect disconnects from the device

func (*Connection) IsConnected

func (c *Connection) IsConnected() bool

IsConnected returns whether the connection is active

func (*Connection) ReadFrame

func (c *Connection) ReadFrame(ctx context.Context, timeout time.Duration) ([]byte, error)

ReadFrame waits for the next notification frame, up to timeout.

func (*Connection) Request

func (c *Connection) Request(ctx context.Context, frame []byte, timeout time.Duration) ([]byte, error)

Request writes a frame and waits for the response notification. Any stale notifications queued before the write are discarded.

func (*Connection) Scan

func (c *Connection) Scan(ctx context.Context, duration time.Duration) ([]bluetooth.ScanResult, error)

Scan scans for nearby battery devices

func (*Connection) WriteFrame

func (c *Connection) WriteFrame(_ context.Context, frame []byte) error

WriteFrame writes a raw frame to the device's write characteristic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL