086c797e0f
This changes the previous raw advertisement packets to structured advertisement configuration. That means you can set the local name not with a raw byte array but with a normal string. While this departs a bit from the original low-level interface as is often used on microcontroller BLE stacks, it is certainly easier to use and better matches higher level APIs that are commonly provided by general-purpose operating systems. If there is a need for raw BLE packets (for baremetal systems only), this can easily be added in the future.
32 lines
586 B
Go
32 lines
586 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.NewAdvertisement()
|
|
must("config adv", adv.Configure(bluetooth.AdvertisementOptions{
|
|
LocalName: "Go Bluetooth",
|
|
Interval: bluetooth.NewAdvertisementInterval(100),
|
|
}))
|
|
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())
|
|
}
|
|
}
|