Documentation
¶
Overview ¶
Package voltgo provides a Go library for communicating with Voltgo and compatible LiFePO4 batteries via Bluetooth Low Energy (BLE).
These batteries are sold under various brand names including Enerwatt, TCED Worldwide, and others, but use the same BLE protocol compatible with the Voltgo mobile app.
This library implements the BLE protocol used by the Voltgo mobile app to monitor and control LiFePO4 battery management systems (BMS).
Basic usage:
client, err := voltgo.NewClient()
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Scan for batteries (raw results carry the address needed to connect)
results, err := client.ScanRaw(ctx, 10*time.Second)
if err != nil {
log.Fatal(err)
}
// Connect to a device
battery, err := client.Connect(ctx, results[0].Address)
if err != nil {
log.Fatal(err)
}
defer battery.Disconnect()
// Read battery status
status, err := battery.GetStatus(ctx)
if err != nil {
log.Fatal(err)
}
The library is organized into several packages:
- battery: Data structures for battery status, cell information, and device info
- ble: Low-level BLE connection handling and characteristic I/O
- protocol: Modbus RTU framing and register parsing
Protocol Details:
The BLE protocol uses the following UUIDs:
- Service: 00001006-0000-1000-8000-00805f9b34fb
- Write: 00001008-0000-1000-8000-00805f9b34fb
- Notify: 00001007-0000-1000-8000-00805f9b34fb
The batteries speak Modbus RTU framed over GATT: a standard Modbus read-holding-registers request (slave address 0x01, function 0x03, CRC-16/MODBUS) is written to the write characteristic, and the response frame arrives as a notification on the notify characteristic. Frames with an invalid CRC are silently ignored by the BMS. See PROTOCOL.md for the register map.
Index ¶
- Constants
- type Battery
- func (b *Battery) Disconnect() error
- func (b *Battery) GetBMSInfo(ctx context.Context) (*protocol.BMSInfo, error)
- func (b *Battery) GetCellVoltages(ctx context.Context) ([]battery.Cell, error)
- func (b *Battery) GetDeviceInfo(ctx context.Context) (*protocol.DeviceInfo, error)
- func (b *Battery) GetInfo(ctx context.Context) (*battery.Info, error)
- func (b *Battery) GetStatus(ctx context.Context) (*battery.Status, error)
- func (b *Battery) IsConnected() bool
- func (b *Battery) ReadRegisters(ctx context.Context, startReg, count uint16) ([]uint16, error)
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context, address bluetooth.Address) (*Battery, error)
- func (c *Client) ConnectByIndex(ctx context.Context, results []bluetooth.ScanResult, index int) (*Battery, error)
- func (c *Client) Scan(ctx context.Context, duration time.Duration) ([]battery.DeviceInfo, error)
- func (c *Client) ScanRaw(ctx context.Context, duration time.Duration) ([]bluetooth.ScanResult, error)
Constants ¶
const ( DefaultTimeout = 5 * time.Second DefaultScanDuration = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Battery ¶
type Battery struct {
// contains filtered or unexported fields
}
Battery represents a connected battery
func (*Battery) Disconnect ¶
Disconnect disconnects from the battery
func (*Battery) GetBMSInfo ¶
GetBMSInfo reads and parses the status register block. This is the low-level variant of GetStatus and includes the raw registers.
func (*Battery) GetCellVoltages ¶
GetCellVoltages retrieves individual cell voltages
func (*Battery) GetDeviceInfo ¶
GetDeviceInfo reads the ASCII device-info register block.
func (*Battery) GetInfo ¶
GetInfo retrieves battery identity information: chemistry and nominal voltage derived from the cell count, plus the device's ASCII identity strings (model, hardware version, manufacture date).
func (*Battery) IsConnected ¶
IsConnected returns whether the battery is connected
func (*Battery) ReadRegisters ¶
ReadRegisters reads count holding registers starting at startReg. This is the low-level primitive underlying all queries; the battery silently ignores malformed requests, which surfaces here as a timeout.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main client for communicating with Voltgo batteries
func (*Client) ConnectByIndex ¶
func (c *Client) ConnectByIndex(ctx context.Context, results []bluetooth.ScanResult, index int) (*Battery, error)
ConnectByIndex connects to a battery device by scan result index