Minimal package for creating and parsing BTHome service data using Go/TinyGo.
// create the data payload
buf := &bthome.Payload{}
// add some data
value := bthome.NewDataValue(bthome.Acceleration)
value.Set(float32(1.23))
err := buf.AddData(value)
if err != nil {
t.Error(err)
}
// now publish the bluetooth.ServiceDataElement
data := buf.ServiceData()
data := []byte{...}
buf := bthome.NewPayload(data)
values, _ := buf.Parse()
for _, v := range values {
println(v.Type().Name(), v.Get())
}
Thermometer beacon device written using TinyGo
$ tinygo flash -target nano-rp2040 -monitor ./examples/thermometer/
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
advertising...
Go BTHome / D2:00:10:09:05:0A
Go BTHome / D2:00:10:09:05:0A
...
Scans for any devices that are advertising BTHome packets, then displays the data.
go run ./cmd/bthomescan
$ go run ./cmd/bthomescan/
scanning...
...
found device: 58:BF:25:3A:EB:D2 -50 Go BTHome
BTHome device found
temperature: 18.5
...
found device: 58:BF:25:3A:EB:D2 -50 Go BTHome
BTHome device found
temperature: 15.400001
...
found device: 58:BF:25:3A:EB:D2 -51 Go BTHome
BTHome device found
temperature: 24.6
- Encryption
- Events