![Ayke van Laethem](/assets/img/avatar_default.png)
Use a new Duration type, which is used throughout the BLE stack for durations. The resolutions are sometimes different (connection parameters have half the resolution) but overall it should improve the ease of use of this type. This commit also provides a default advertisement interval that is recommended by Apple (which I think is as good as any recommendation). This might help to speed up discovery by Apple (and Android?) phones.
31 lines
536 B
Go
31 lines
536 B
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/tinygo-org/bluetooth"
|
|
)
|
|
|
|
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...")
|
|
for {
|
|
// Sleep forever.
|
|
time.Sleep(time.Hour)
|
|
}
|
|
}
|
|
|
|
func must(action string, err error) {
|
|
if err != nil {
|
|
panic("failed to " + action + ": " + err.Error())
|
|
}
|
|
}
|