如何从蓝牙中读取特性?

问题描述 投票:0回答:1

我试图从蓝牙中读取特征:

service uuid: 00001800-0000-1000-8000-00805f9b34fb
characteristic uuid: 00002a00-0000-1000-8000-00805f9b34fb

我不知道如何调用chr_get_valuechr_read的那些方法。我知道关键是gdbus

bluetooth-lowenergy bluez bluetooth-gatt
1个回答
0
投票

您提到的服务UUID是GAP(通用访问配置文件)服务UUID,您尝试读取的特征UUID(00002a00-0000-1000-8000-00805f9b34fb)是设备名称特征,并返回远程LE设备的设备名称。

bluez在其DBus API上公开了它的所有功能。如果要在DBus和C中执行此操作,首先需要了解DBus协议和libdbus或任何其他DBus绑定API。

有关文档和python示例,请参阅bluez源目录中的doc / gatt-api.txt和test / example-gatt-client。 test / example-gatt-client有一个很好的python示例,可以帮助您了解如何扫描,查找和读取设备的特征。

否则,如果您知道要连接的设备的BD_ADDR地址(蓝牙设备地址),则可以使用bluez的gatttool工具执行此任务。

例如,如果地址是03:0F:45:65:43:FF并且您的设备hci接口地址是hci0,则下面的命令序列读取2a00特征

[03:0F:45:65:43:FF][LE]> connect
Attempting to connect to 03:0F:45:65:43:FF
Connection successful

[03:0F:45:65:43:FF][LE]> primary
attr handle: 0x0001, end grp handle: 0x0005 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0006, end grp handle: 0x0009 uuid: 00001801-0000-1000-8000-00805f9b34fb
# lists all other primary services

[03:0F:45:65:43:FF][LE]> characteristics
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
# lists all other characteristics as well

[03:0F:45:65:43:FF][LE]> char-read-uuid 2a00
handle: 0x0003   value: 4d 79 20 6e 61 6d 65
© www.soinside.com 2019 - 2024. All rights reserved.