-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathbleclient_generic_access.go
More file actions
55 lines (43 loc) · 1002 Bytes
/
bleclient_generic_access.go
File metadata and controls
55 lines (43 loc) · 1002 Bytes
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
54
55
//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_generic_access.go BB-1234
NOTE: sudo is required to use BLE in Linux
*/
package main
import (
"fmt"
"os"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/ble"
"gobot.io/x/gobot/v2/platforms/bleclient"
)
func main() {
bleAdaptor := bleclient.NewAdaptor(os.Args[1], bleclient.WithScanTimeout(30*time.Second), bleclient.WithDebug())
access := ble.NewGenericAccessDriver(bleAdaptor)
work := func() {
devName, err := access.GetDeviceName()
if err != nil {
fmt.Println(err)
}
fmt.Println("Device name:", devName)
appearance, err := access.GetAppearance()
if err != nil {
fmt.Println(err)
}
fmt.Println("Appearance:", appearance)
}
robot := gobot.NewRobot("bleBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{access},
work,
)
if err := robot.Start(); err != nil {
panic(err)
}
}