-
Notifications
You must be signed in to change notification settings - Fork 64
/
Notes.txt
115 lines (77 loc) · 3.15 KB
/
Notes.txt
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
My adventures in bluetooth with the BLE112 devkit.
Note, my machine is called "sheepfrog" http://en.wikipedia.org/wiki/Sheep_frog
Get list of adapters:
$bt-adapter -l
Available adapters:
sheepfrog-0 (88:9F:FA:EC:27:8F)
sheepfrog-1 (00:02:72:3E:A5:07)
bt-adapter uses DBUS/GObject interface to bluez and is so far impenetrable.
Not yet found libbluetooth C API call which does this. Kernel call exists, but not C API?
Find device:
$bt-adapter -a sheepfrog-1 -d
Searching...
[3C:2D:B7:85:50:2A]
Name: DKBLE112 thermometer
Alias: DKBLE112 thermometer
Address: 3C:2D:B7:85:50:2A
(bt-adapter:31979): GLib-GObject-CRITICAL **: g_value_get_string: assertion `G_VALUE_HOLDS_STRING (value)' failed
Icon: (null)
Class: 0x0
LegacyPairing: 0
Paired: 0
RSSI: -68
[7C:E9:D3:E4:3F:7C]
Name: LAWRENCE-THINK
Alias: LAWRENCE-THINK
Address: 7C:E9:D3:E4:3F:7C
Icon: computer
Class: 0x3e010c
LegacyPairing: 0
Paired: 0
RSSI: -88
Done
Or, alternatively, use hcitool:
hcitool -i hci1 scan
does not work (why?). Whereas:
$ sudo hcitool lescan
LE Scan ...
3C:2D:B7:85:50:2A (unknown)
3C:2D:B7:85:50:2A DKBLE112 thermometer
For some reason only lescan picks up BLE devices. Also, lescan knows which
device to use (presumably because only one of my adapters supports BLE, so it
skips over the first one??). Also for some reason, root is needed to initiate LE
scan.
Now to connect:
(I for interactive mode). Anything before > is the prompt. # are my comments
$ gatttool -b 3C:2D:B7:85:50:2A -I
[ ][3C:2D:B7:85:50:2A][LE]> connect
[CON][3C:2D:B7:85:50:2A][LE]>
# From here:
# http://stackoverflow.com/questions/15657007/bluetooth-low-energy-listening-for-notifications-indications-in-linux
# Then type char-read-uuid 2902. You should get a list of all CCC (Client
# Characteristic Configuration) attributes on the device
# see also http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
#
[CON][3C:2D:B7:85:50:2A][LE]> char-read-uuid 2902
[CON][3C:2D:B7:85:50:2A][LE]>
handle: 0x0012 value: 00 00
[CON][3C:2D:B7:85:50:2A][LE]>
#Switch on indications...
[CON][3C:2D:B7:85:50:2A][LE]> char-write-cmd 12 0200
Indication handle = 0x0010 value: 00 2f 01 00 ff
Indication handle = 0x0010 value: 00 2f 01 00 ff
Indication handle = 0x0010 value: 00 2f 01 00 ff
Indication handle = 0x0010 value: 00 31 01 00 ff
# 2f 01, 31 01 is temperature in degrees C / 10 in little endian order. i.e.
# x2f + xff*x1 = d303 i.e. 30.3 degrees C.
Ah ha!
https://www.bluetooth.org/en-us/specification/assigned-numbers-overview/generic-attribute-profile
Magic number 2902 is the "client characteristic specification"
More docs:
http://developer.bluetooth.org/TechnologyOverview/Pages/BLE.aspx
So, it seems that Generic Attribute Profile (GATT) is the way of communicating
with BLE devices. Or at least it's a standard way of doing it. Presumably one
could use lower layers, but that's making life hard. I won't try. Actually,
apparently GATT and ATT are mandatory in BLE.
Documents about the generic attribute profile are here:
http://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx