-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (31 loc) · 774 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"time"
"tinygo.org/x/bluetooth"
)
var adapter = bluetooth.DefaultAdapter
func main() {
time.Sleep(time.Second)
println("Enabling stack in 3 .. 2 .. 1")
time.Sleep(3 * time.Second)
println("Enabling BLE stack")
must("enable BLE stack", adapter.Enable())
time.Sleep(1 * time.Second)
println("advertising...")
adv := adapter.DefaultAdvertisement()
must("config adv", adv.Configure(bluetooth.AdvertisementOptions{
LocalName: "Go Bluetooth",
}))
must("start adv", adv.Start())
address, _ := adapter.Address()
for {
println("Go Bluetooth /", address.MAC.String())
// println("tick")
time.Sleep(time.Second)
}
}
func must(action string, err error) {
if err != nil {
panic("failed to " + action + ": " + err.Error())
}
}