1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00
hybridgroup.gobot/examples/ble_device_info.go
Thomas Kohler 865e724af0
Build(v2): revert move to v2 subfolder (#932)
* revert move to v2 subfolder
* fix CI and adjust CHANGELOG
2023-05-29 19:23:28 +02:00

46 lines
871 B
Go

//go:build example
// +build example
//
// Do not build by default.
/*
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
*/
package main
import (
"fmt"
"os"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/ble"
)
func main() {
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
info := ble.NewDeviceInformationDriver(bleAdaptor)
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,
)
robot.Start()
}