2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-06-10 19:18:29 +08: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 18:46:29 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/ble"
|
2016-07-03 18:46:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
|
|
info := ble.NewDeviceInformationDriver(bleAdaptor)
|
2016-07-03 18:46:29 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
fmt.Println("Model number:", info.GetModelNumber())
|
|
|
|
fmt.Println("Firmware rev:", info.GetFirmwareRevision())
|
|
|
|
fmt.Println("Hardware rev:", info.GetHardwareRevision())
|
|
|
|
fmt.Println("Manufacturer name:", info.GetManufacturerName())
|
|
|
|
fmt.Println("PnPId:", info.GetPnPId())
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{info},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2016-07-03 18:46:29 +08:00
|
|
|
}
|