2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2017-03-13 11:01:39 -04:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-06-10 13:18:29 +02:00
|
|
|
/*
|
|
|
|
How to run
|
|
|
|
Pass the Bluetooth address or name as the first param:
|
|
|
|
|
|
|
|
go run examples/ble_device_info.go BB-1234
|
|
|
|
|
|
|
|
NOTE: sudo is required to use BLE in Linux
|
|
|
|
*/
|
|
|
|
|
2016-07-03 12:46:29 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
2024-02-04 18:50:43 +01:00
|
|
|
"gobot.io/x/gobot/v2/drivers/ble"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/bleclient"
|
2016-07-03 12:46:29 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-04 18:50:43 +01:00
|
|
|
bleAdaptor := bleclient.NewAdaptor(os.Args[1])
|
2016-10-03 16:58:43 +02:00
|
|
|
info := ble.NewDeviceInformationDriver(bleAdaptor)
|
2016-07-03 12:46:29 +02:00
|
|
|
|
|
|
|
work := func() {
|
2024-02-10 18:02:09 +01:00
|
|
|
modelNo, err := info.GetModelNumber()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Model number:", modelNo)
|
|
|
|
|
|
|
|
fwRev, err := info.GetFirmwareRevision()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Firmware rev:", fwRev)
|
|
|
|
|
|
|
|
hwRev, err := info.GetHardwareRevision()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Hardware rev:", hwRev)
|
|
|
|
|
|
|
|
manuName, err := info.GetManufacturerName()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Manufacturer name:", manuName)
|
|
|
|
|
|
|
|
pid, err := info.GetPnPId()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("PnPId:", pid)
|
2016-07-03 12:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{info},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-07-03 12:46:29 +02:00
|
|
|
}
|