prototooth/examples/advertisement/main.go
2022-08-20 18:44:14 -07:00

32 lines
601 B
Go

package main
import (
"time"
"git.tcp.direct/kayos/prototooth"
)
var adapter = bluetooth.DefaultAdapter
func main() {
must("enable BLE stack", adapter.Enable())
adv := adapter.DefaultAdvertisement()
must("config adv", adv.Configure(bluetooth.AdvertisementOptions{
LocalName: "Go Bluetooth",
}))
must("start adv", adv.Start())
println("advertising...")
address, _ := adapter.Address()
for {
println("Go Bluetooth /", address.MAC.String())
time.Sleep(time.Second)
}
}
func must(action string, err error) {
if err != nil {
panic("failed to " + action + ": " + err.Error())
}
}