forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ble_multiple_generic.go
53 lines (40 loc) · 920 Bytes
/
ble_multiple_generic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// +build example
//
// Do not build by default.
/*
How to run
Pass the Bluetooth address or name as the first param:
go run examples/ble_multiple_generic.go BB-1234 BB-1235
NOTE: sudo is required to use BLE in Linux
*/
package main
import (
"fmt"
"os"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
"gobot.io/x/gobot/platforms/ble"
)
func NewSwarmBot(port string) *gobot.Robot {
bleAdaptor := ble.NewClientAdaptor(port)
access := ble.NewGenericAccessDriver(bleAdaptor)
work := func() {
fmt.Println("Device name:", access.GetDeviceName())
fmt.Println("Appearance:", access.GetAppearance())
}
robot := gobot.NewRobot("bot "+port,
[]gobot.Connection{bleAdaptor},
[]gobot.Device{access},
work,
)
return robot
}
func main() {
master := gobot.NewMaster()
api.NewAPI(master).Start()
for _, port := range os.Args[1:] {
bot := NewSwarmBot(port)
master.AddRobot(bot)
}
master.Start()
}