lin*_*sek 13 bluetooth bluetooth-lowenergy bluez gatt
我正在为BLE演示设置两个Linux系统.显然,一个系统将是外围设备,一个系统将是中央设备.围绕这两种配置我有几个问题.
环境
外围设备设置
第一项业务是通过配置的GATT服务器获得外围系统设置和广告.此时,似乎无法从命令行配置GATT服务器.因此,虽然将USB加密狗带入并通告它是一项简单的任务,但这不允许创建自定义服务和特性.我能找到的GATT服务器的唯一例子是Bluez包中的gatt-example.c文件.所以我下载并构建了最新的bluez-5.23源代码.(http://www.linuxfromscratch.org/blfs/view/svn/general/bluez.html).另外使用--enable-maintainer-mode标志配置强制将gatt-example.c插件构建到bluetoothd中.我从~/bluez-5.23/plugins目录中验证了有bluetoothd-gat-example.o文件的后期构建.这告诉我gatt-example至少是成功构建的.
然后我修改了配置文件以启用LE和属性服务器.
$ sudo vi /etc/bluetooth/main.conf
EnableLE = true // Enable Low Energy support. Default is false.
AttributeServer = true // Enable the GATT attribute server. Default is false.
Run Code Online (Sandbox Code Playgroud)
然后只需重启或重启蓝牙守护进程......
中央设备设置
由于中央设备不需要像外围设备那样构建任何特殊插件,我只使用了bluez apt-get.这似乎已根据安装v4.101 bluetoothd -v.
会话设置
然后连接过程应该相当简单.我设置外围设备进行广告宣传,然后与中央设备连接:
外围:
$ sudo hciconfig hci0 up // Make sure the interface is up
$ sudo hciconfig hci0 leadv // Set the interface to advertise
Run Code Online (Sandbox Code Playgroud)
中央:
$ sudo hcitool -i hci0 lescan // Scan for nearby devices advertising
LE Scan ...
00:02:72:C9:5E:0F (unknown) // Not sure why two of the same MAC are found?
00:02:72:C9:5E:0F (unknown) // but I know this is my device...
$ sudo gatttool -i hci0 -b 00:02:72:C9:5E:0F -m 48 --interactive // Connect interactively
[ ][00:02:72:C9:5E:0F][LE]> connect
[CON][00:02:72:C9:5E:0F][LE]> primary
attr handle: 0x0001, end grp handle: 0x0008 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0010, end grp handle: 0x0010 uuid: 00001801-0000-1000-8000-00805f9b34fb
[CON][00:02:72:C9:5E:0F][LE]> characteristics
handle: 0x0004, char properties: 0x02, char value handle: 0x0006, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0007, char properties: 0x02, char value handle: 0x0008, uuid: 00002a01-0000-1000-8000-00805f9b34fb
Run Code Online (Sandbox Code Playgroud)
我们看不到gatt-example的服务或特性之一可用.
问题
- 外围设备
- 中央设备
我可以提供任何必要的额外信息.谢谢.
要将 GATT 服务器创建到单独的进程中,您(至少)有两种情况:
如果您的中央设备看不到新导出的 GATT 服务,则可能是外设上的问题,而不是中央设备上的问题。当您需要在中央设备上实施 GATT 客户端时,您仍然有两种情况:
gatttool等 GATT 库与 BLE 设备交互