2019-06-02 17:12:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2020-05-31 14:45:26 +00:00
|
|
|
"github.com/tinygo-org/bluetooth"
|
2019-06-02 17:12:36 +00:00
|
|
|
)
|
|
|
|
|
2020-06-01 11:26:45 +00:00
|
|
|
var adapter = bluetooth.DefaultAdapter
|
|
|
|
|
2019-06-02 17:12:36 +00:00
|
|
|
func main() {
|
2020-06-01 11:26:45 +00:00
|
|
|
must("enable BLE stack", adapter.Enable())
|
2019-06-02 17:12:36 +00:00
|
|
|
adv := adapter.NewAdvertisement()
|
2020-06-01 12:07:07 +00:00
|
|
|
must("config adv", adv.Configure(bluetooth.AdvertisementOptions{
|
|
|
|
LocalName: "Go Bluetooth",
|
|
|
|
Interval: bluetooth.NewAdvertisementInterval(100),
|
|
|
|
}))
|
2019-06-02 17:12:36 +00:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|