forked from muka/go-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
61 lines (45 loc) · 1.26 KB
/
test.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
54
55
56
57
58
59
60
61
package main
import (
"github.com/godbus/dbus"
"github.com/tj/go-debug"
)
var dbg = debug.Debug("dbus:test")
// read sensor tag temperature
func testrun() {
conn, err := dbus.SystemBus()
if err != nil {
panic(err)
}
ns := "org.bluez"
//
temperatureDataPath := "/org/bluez/hci0/dev_B0_B4_48_C9_4B_01/service0022/char0023"
temperatureConfigPath := "/org/bluez/hci0/dev_B0_B4_48_C9_4B_01/service0022/char0026"
writeCall := "org.bluez.GattCharacteristic1.WriteValue"
readCall := "org.bluez.GattCharacteristic1.ReadValue"
// write, enable measurements
opts := make(map[string]dbus.Variant)
dbg("Enable measurment")
b := []byte{0x01}
temperatureConfig := conn.Object(ns, dbus.ObjectPath(temperatureConfigPath))
call := temperatureConfig.Call(writeCall, 0, b, opts)
if call.Err != nil {
dbg("Error: %s", call.Err)
panic(call.Err)
}
// read
dbg("Read data")
temperatureData := conn.Object(ns, dbus.ObjectPath(temperatureDataPath))
call = temperatureData.Call(readCall, 0, opts)
if call.Err != nil {
dbg("Error: %s", call.Err)
panic(call.Err)
}
dbg("Result %v", call.Body)
dbg("Disable measurment")
b = []byte{0x00}
call = temperatureConfig.Call(writeCall, 0, b, opts)
if call.Err != nil {
dbg("Error: %s", call.Err)
panic(call.Err)
}
}