我偶然发现了这个问题:Reading Thermometer Data with Bluez Bluetooth Low Energy ,并试图从我得到的蓝牙温度计中读取数据。
我能够使用以下命令提取和读取所有句柄:
gatttool -b 00:11:22:33:44:55 -I
[00:11:22:33:44:55][LE]> connect
Connection successful
[00:11:22:33:44:55][LE]> primary
attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0008, end grp handle: 0x000b uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x001e uuid: 0000180a-0000-1000-8000-00805f9b34fb
attr handle: 0x001f, end grp handle: 0xffff uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
[00:11:22:33:44:55][LE]> char-desc 0x0001 0x0001
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
[00:11:22:33:44:55][LE]> char-desc 0x0001 0x0007
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb
[00:11:22:33:44:55][LE]> char-read-hnd 01
Characteristic value/descriptor: 00 18
[00:11:22:33:44:55][LE]> char-read-hnd 02
Characteristic value/descriptor: 02 03 00 00 2a
[00:11:22:33:44:55][LE]> char-read-hnd 03
Characteristic value/descriptor: 54 68 65 72 6d 6f 42 65 61 63 6f 6e
[00:11:22:33:44:55][LE]> char-read-hnd 04
Characteristic value/descriptor: 02 05 00 01 2a
[00:11:22:33:44:55][LE]> char-read-hnd 05
Characteristic value/descriptor: 00 00
[00:11:22:33:44:55][LE]> char-read-hnd 06
Characteristic value/descriptor: 02 07 00 04 2a
[00:11:22:33:44:55][LE]> char-read-hnd 07
Characteristic value/descriptor: 50 00 a0 00 00 00 e8 03
[00:11:22:33:44:55][LE]> char-desc 0x0008 0x000b
handle: 0x0008, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0009, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x000a, uuid: 00002a05-0000-1000-8000-00805f9b34fb
handle: 0x000b, uuid: 00002902-0000-1000-8000-00805f9b34fb
[00:11:22:33:44:55][LE]> char-read-hnd 08
Characteristic value/descriptor: 01 18
[00:11:22:33:44:55][LE]> char-read-hnd 09
Characteristic value/descriptor: 20 0a 00 05 2a
[00:11:22:33:44:55][LE]> char-read-hnd 0a
Error: Characteristic value/descriptor read failed: Attribute can't be read
[00:11:22:33:44:55][LE]> char-read-hnd 0b
Characteristic value/descriptor: 00 00
[00:11:22:33:44:55][LE]> char-desc 0x000c 0x001e
handle: 0x000c, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x000d, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x000e, uuid: 00002a23-0000-1000-8000-00805f9b34fb
handle: 0x000f, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0010, uuid: 00002a24-0000-1000-8000-00805f9b34fb
handle: 0x0011, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0012, uuid: 00002a25-0000-1000-8000-00805f9b34fb
handle: 0x0013, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0014, uuid: 00002a26-0000-1000-8000-00805f9b34fb
handle: 0x0015, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0016, uuid: 00002a27-0000-1000-8000-00805f9b34fb
handle: 0x0017, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0018, uuid: 00002a28-0000-1000-8000-00805f9b34fb
handle: 0x0019, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001a, uuid: 00002a29-0000-1000-8000-00805f9b34fb
handle: 0x001b, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001c, uuid: 00002a2a-0000-1000-8000-00805f9b34fb
handle: 0x001d, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001e, uuid: 00002a50-0000-1000-8000-00805f9b34fb
[00:11:22:33:44:55][LE]> char-read-hnd 0c
Characteristic value/descriptor: 0a 18
[00:11:22:33:44:55][LE]> char-read-hnd 0d
Characteristic value/descriptor: 02 0e 00 23 2a
[00:11:22:33:44:55][LE]> char-read-hnd 0e
Characteristic value/descriptor: 5e 0b 00 00 00 00 f4 00
[00:11:22:33:44:55][LE]> char-read-hnd 0f
Characteristic value/descriptor: 02 10 00 24 2a
[00:11:22:33:44:55][LE]> char-read-hnd 10
Characteristic value/descriptor: 4d 6f 64 65 6c 20 4e 75 6d 62 65 72
[00:11:22:33:44:55][LE]> char-read-hnd 11
Characteristic value/descriptor: 02 12 00 25 2a
[00:11:22:33:44:55][LE]> char-read-hnd 12
Characteristic value/descriptor: 53 65 72 69 61 6c 20 4e 75 6d 62 65 72
[00:11:22:33:44:55][LE]> char-read-hnd 13
Characteristic value/descriptor: 02 14 00 26 2a
[00:11:22:33:44:55][LE]> char-read-hnd 14
Characteristic value/descriptor: 46 69 72 6d 77 61 72 65 20 52 65 76 69 73 69 6f 6e
[00:11:22:33:44:55][LE]> char-read-hnd 15
Characteristic value/descriptor: 02 16 00 27 2a
[00:11:22:33:44:55][LE]> char-read-hnd 16
其中一些喜欢例如在使用 HEX 转换为 ASCII 转换器时逐个字母4d 61 6e 75 66 61 63 74 75 72 65 72 20 4e 61 6d 65
读取,但其中一些喜欢例如使用一些空白方块Manufacturer Name
02 1c 00 2a 2a read
**
我还尝试将一些数字转换为十进制以尝试获得温度值,但没有运气。
每次读取它们时值都保持不变,所以我想这不是读取温度值的方法。
我是否必须以某种方式从这些句柄请求数据。如何从我上面的数据中找到温度值?
当我读到这个温度是从 19.8 到 20.2°C 时,类似的东西(如果它隐藏在我上面列出的那些值中的某个地方)
我只想从中读出温度值。
更新:
打开后scan on
,bluetoothctl
我从蓝牙温度计获取了这个数据包:
[CHG] Device 00:11:22:33:44:55 RSSI: -81
[CHG] Device 00:11:22:33:44:55 TxPower: 0
[CHG] Device 00:11:22:33:44:55 ManufacturerData Key: 0x0011
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 24 0c 43 01 75 04 f3 5b ..^.....$.C.u..[
01 00 ..
[CHG] Device 00:11:22:33:44:55 ManufacturerData Key: 0x0011
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 23 0c 43 01 79 04 02 5c ..^.....#.C.y..\
01 00 ..
[CHG] Device 00:11:22:33:44:55 RSSI: -63
[CHG] Device 00:11:22:33:44:55 ManufacturerData Key: 0x0011
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 8c 01 2a 3d 00 00 34 01 ..^.......*=..4.
c3 40 01 00 .@..
[CHG] Device 00:11:22:33:44:55 RSSI: -81
[CHG] Device 00:11:22:33:44:55 ManufacturerData Key: 0x0011
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 24 0c 44 01 75 04 22 5c ..^.....$.D.u."\
01 00 ..
[CHG] Device 00:11:22:33:44:55 RSSI: -54
[CHG] Device 00:11:22:33:44:55 ManufacturerData Key: 0x0011
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 8c 01 2a 3d 00 00 34 01 ..^.......*=..4.
c3 40 01 00
让我们获取第一组数据:
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 24 0c 43 01 75 04 f3 5b ..^.....$.C.u..[
01 00
我注意到跳过了55 44 33 22 11 00
设备的前 2 个字节 MAC 地址,但相反。
之后该24 0c
部分在其他集合中类似地重复,例如在下一个中23 0c
。
接下来的 2 个字节43 01
(这是我计算温度的方法。反转字节顺序 -> 01 43
-> 0x0143
->323
十进制 -> 323/16
->20.1875
向上20.2
舍入。这是我的温度计上的准确温度,我在温度越来越高时尝试过,它总是显示准确的温度。
同样,接下来的两个75 04
:0x0475
->1141
十进制-> 1141/16
=71.3125
向下舍入71%->温度计上显示的湿度
这是正确的解释吗?
让我感到困惑的是第三组数据更长,数据包在这两者之间交替:
[CHG] Device 00:11:22:33:44:55 RSSI: -63
[CHG] Device 00:11:22:33:44:55 ManufacturerData Key: 0x0011
[CHG] Device 00:11:22:33:44:55 ManufacturerData Value:
00 00 55 44 33 22 11 00 8c 01 2a 3d 00 00 34 01 ..^.......*=..4.
c3 40 01 00
那是温度计发送的其他数据吗?