2020-05-28 00:13:04 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-07-31 22:38:08 +03:00
|
|
|
"gitrepo.ru/neonxp/bluetooth"
|
2020-05-28 00:13:04 +03:00
|
|
|
)
|
|
|
|
|
2020-06-01 14:26:45 +03:00
|
|
|
var adapter = bluetooth.DefaultAdapter
|
|
|
|
|
2020-05-28 00:13:04 +03:00
|
|
|
func main() {
|
|
|
|
// Enable BLE interface.
|
2020-06-01 14:26:45 +03:00
|
|
|
must("enable BLE stack", adapter.Enable())
|
2020-05-28 00:13:04 +03:00
|
|
|
|
|
|
|
// Start scanning.
|
|
|
|
println("scanning...")
|
2020-06-01 14:26:45 +03:00
|
|
|
err := adapter.Scan(func(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {
|
2020-05-28 00:13:04 +03:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|