gobot.io/x/gobot/v2@v2.1.0/examples/ble_multiple_info.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 /* 8 How to run 9 Pass the Bluetooth address or name as the first param: 10 11 go run examples/ble_multiple_info.go BB-1234 BB-1235 12 13 NOTE: sudo is required to use BLE in Linux 14 */ 15 16 package main 17 18 import ( 19 "fmt" 20 "os" 21 22 "gobot.io/x/gobot/v2" 23 "gobot.io/x/gobot/v2/api" 24 "gobot.io/x/gobot/v2/platforms/ble" 25 ) 26 27 func NewSwarmBot(port string) *gobot.Robot { 28 bleAdaptor := ble.NewClientAdaptor(port) 29 info := ble.NewDeviceInformationDriver(bleAdaptor) 30 31 work := func() { 32 fmt.Println("Model number:", info.GetModelNumber()) 33 fmt.Println("Firmware rev:", info.GetFirmwareRevision()) 34 fmt.Println("Hardware rev:", info.GetHardwareRevision()) 35 fmt.Println("Manufacturer name:", info.GetManufacturerName()) 36 fmt.Println("PnPId:", info.GetPnPId()) 37 } 38 39 robot := gobot.NewRobot("bot "+port, 40 []gobot.Connection{bleAdaptor}, 41 []gobot.Device{info}, 42 work, 43 ) 44 45 return robot 46 } 47 48 func main() { 49 master := gobot.NewMaster() 50 api.NewAPI(master).Start() 51 52 for _, port := range os.Args[1:] { 53 bot := NewSwarmBot(port) 54 master.AddRobot(bot) 55 } 56 57 master.Start() 58 }