prototooth/examples/advertisement/main.go
Ayke van Laethem 0474d7b750
all: change DefaultAdapter function to global
All initialization can be done in the Enable call. This makes the API a
bit simpler and a bit more consistent between Nordic chips and other BLE
interfaces.
2020-06-01 13:27:56 +02:00

35 lines
668 B
Go

package main
import (
"time"
"github.com/tinygo-org/bluetooth"
)
// flags + local name
var advPayload = []byte("\x02\x01\x06" + "\x07\x09TinyGo")
var adapter = bluetooth.DefaultAdapter
func main() {
must("enable BLE stack", adapter.Enable())
adv := adapter.NewAdvertisement()
options := &bluetooth.AdvertiseOptions{
Interval: bluetooth.NewAdvertiseInterval(100),
}
must("config adv", adv.Configure(advPayload, nil, options))
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())
}
}