https://github.com/hybridgroup/go-bthome
Minimal package for creating and parsing BTHome service data using Go/TinyGo.
https://github.com/hybridgroup/go-bthome
Last synced: about 2 months ago
JSON representation
Minimal package for creating and parsing BTHome service data using Go/TinyGo.
- Host: GitHub
- URL: https://github.com/hybridgroup/go-bthome
- Owner: hybridgroup
- Created: 2025-01-05T09:56:23.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-01-07T06:34:30.000Z (4 months ago)
- Last Synced: 2025-01-23T08:35:41.112Z (3 months ago)
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-tinygo - go-bthome - Minimal package for creating and parsing BTHome service data using Go/TinyGo. (Embedded Systems / Protocol implementations)
README
# go-bthome
Minimal package for creating and parsing [BTHome](https://bthome.io/) service data using Go/TinyGo.
## How to use
### Create a BTHome Payload
```go
// 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()
```### Parse a BTHome Payload
```go
data := []byte{...}
buf := bthome.NewPayload(data)
values, _ := buf.Parse()
for _, v := range values {
println(v.Type().Name(), v.Get())
}
```## Examples
### Thermometer
[examples/thermometer](./examples/thermometer)
Thermometer beacon device written using TinyGo
```shell
$ 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
...
```## CLI Tools
### bthomescan
[cmd/bthomescan](./cmd/bthomescan)
Scans for any devices that are advertising BTHome packets, then displays the data.
```shell
go run ./cmd/bthomescan
``````shell
$ 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
```## Missing features
- Encryption
- Events