Bluetooth 使用gatttool从蓝牙温度计读取数据
我偶然发现了这个问题: 然后跟踪它,试图从我得到的蓝牙温度计读取数据 我可以使用此命令提取并读取所有句柄:Bluetooth 使用gatttool从蓝牙温度计读取数据,bluetooth,bluetooth-lowenergy,bluez,gatttool,Bluetooth,Bluetooth Lowenergy,Bluez,Gatttool,我偶然发现了这个问题: 然后跟踪它,试图从我得到的蓝牙温度计读取数据 我可以使用此命令提取并读取所有句柄: 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-
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
例如,当使用十六进制到ASCII转换器进行转换时,有些人喜欢4d 61 6e 75 66 61 63 74 75 72 65 72 20 4e 61 6d 65
逐字读取制造商名称
,但有些人喜欢02 1c 00 2a 2a读取
**
我还尝试将一些数字转换成十进制,以获得温度值,但没有成功
每次我读取它们时,这些值都保持不变,所以我想这不是读取温度值的方法
我是否必须以某种方式从这些句柄请求数据。如何从上述数据中找到温度值
当我读到这个温度是19.8到20.2°C时,类似的情况(如果它隐藏在我上面列出的那些值中)
我只想从中读出温度值,而不是别的
更新:
在打开scan
打开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
我注意到跳过了设备的前2个字节554433221100
MAC地址,但相反
之后,24 0c
零件在其他组中重复类似操作,例如在下一组中,its23 0c
接下来的2个字节(43 01
)是我注意到的随房间温度变化而变化的字节,是表示温度的字节。这是我计算温度的方法。将字节顺序颠倒->0143
->0x0143
->323
以十进制->323/16
->20.1875
向上取整。这是我温度计上的准确温度,我在温度越来越高和越来越低的时候试过,它总是显示准确的温度
类似地,接下来的两个75 04
:0x0475
->1141
十进制->1141/16
=71.3125
向下取整->温度计上显示的湿度
这是正确的解释吗?
让我困惑的是第三组数据更长,数据包在这两组数据之间交替:
[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
这是温度计发送的其他数据吗?作为旁注,当前支持的工具是bluetoothctl
格式为00000XXXX-0000-1000-8000-00805f9b34fb的GATT UUID表示它们已被蓝牙SIG采用,您可以在
还有一些通用的蓝牙低能扫描和探测工具,例如,可以帮助探测设备
从你发布的关贸总协定信息中,我只能看到需要包括的一般内容,而没有任何关于温度的具体内容
广告数据包括制造商数据,制造商数据可以(顾名思义)是制造商想要的任何东西。从
这意味着您需要从制造商处获取信息,或者从您认为数据所说的内容中反向操作。由于您尚未共享有关设备广播的任何信息,因此您的方向似乎是正确的
大多数蓝牙数据都是小端数据,因此必须交换字节也就不足为奇了。像iBeacon和Eddystone这样的信标格式往往是big-endian格式,但它们是例外而不是规则
如果您想将数据转换成某种代码,可能需要使用D-Bus API。大多数语言都有D-Bus绑定,您需要的BlueZ API记录在:
scan on
onbluetoothctl
时,我得到了这个数据:00 55 44 33 22 11 00 30 0c 44 01 36 04 2a cb..0.D.6.*.00
。我注意到,从第三个字节开始,它会打印我的MAC地址,但方向相反。然后我观察了它打印的内容,注意到重复的部分和变化的部分。不知怎的,我强行改变了组合,发现44 01
代表温度和36 04
湿度。我只需要找到一个十进制值0x0144,然后除以16,得到20.2
。这总是这样吗?你介意解释一下我在这里做了什么吗?这是一种正确的方式吗?如果你不介意的话,我用我试图在评论中解释的信息更新了我的帖子。我想你建议的c3
是不正确的,因为当我提取数据时,它正好是20.2
而不是20.3
。