0474d7b750
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.
26 lines
544 B
Go
26 lines
544 B
Go
package main
|
|
|
|
import (
|
|
"github.com/tinygo-org/bluetooth"
|
|
)
|
|
|
|
var adapter = bluetooth.DefaultAdapter
|
|
|
|
func main() {
|
|
// Enable BLE interface.
|
|
must("enable BLE stack", adapter.Enable())
|
|
|
|
// Start scanning.
|
|
println("scanning...")
|
|
err := adapter.Scan(func(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {
|
|
println("found device:", device.Address.String(), device.RSSI, device.LocalName())
|
|
})
|
|
must("start scan", err)
|
|
}
|
|
|
|
func must(action string, err error) {
|
|
if err != nil {
|
|
panic("failed to " + action + ": " + err.Error())
|
|
}
|
|
}
|