我正在为一个BLE演示设置两个Linux系统。显然,一个系统将是外设,另一个将是中心设备。我对这两种配置都有一些问题。
环境
- 2个Ubuntu 14.04系统
- 2个可插入式USB-BT4LE适配器 (http://plugable.com/products/usb-bt4le)
外设配置
首要任务是设置外设系统并使用已配置的GATT服务器进行广告。目前似乎无法通过命令行配置GATT服务器。因此,虽然将USB适配器启动并将其广告化是一项简单的任务,但这并不允许创建自定义服务和特征。我能找到的唯一一个GATT服务器示例是Bluez软件包中的gatt-example.c文件。因此,我下载并构建了最新的bluez-5.23源代码。(http://www.linuxfromscratch.org/blfs/view/svn/general/bluez.html)。此外,还使用--enable-maintainer-mode标志配置bluetoothd以强制构建gatt-example.c插件。我验证了构建后,在~/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.
然后只需重新启动蓝牙守护程序或重启设备...
中心设备设置
由于中心设备不需要像外围设备一样构建任何特殊插件,因此我只是使用apt-get
安装了bluez。根据bluetoothd -v
的输出,这似乎安装了版本4.101。
会话设置
连接过程应该非常简单。我设置了外围设备进行广告并与中心设备连接:
外围设备:
$ sudo hciconfig hci0 up // Make sure the interface is up
$ sudo hciconfig hci0 leadv // Set the interface to advertise
中心:
$ 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
我们看到Gatt示例中的服务或特征都不可用。
问题
--外围设备
- 我该如何创建自己的自定义Gatt服务器?它可以是独立的C应用程序,还是需要像Gatt示例一样作为插件内置于bluetoothd中?这个问题的答案(Creating a Gatt Server?)意味着你可以按照以下步骤进行:"首先初始化Gatt库和其他模块",然后"注册Gatt数据库"。但是没有一个实现这些通用语句的例子,所提供的链接只是蓝牙网站的URL。
- GATT规范(https://developer.bluetooth.org/gatt/Pages/default.aspx)提供了许多可下载的“采用”的服务和特征(以XML格式)。但是没有使用它们的说明?!
- 如何验证我的Gatt服务器正在运行?
--中央设备
- 为什么我的中央设备无法看到外围设备上运行的Gatt服务器的服务和特征?
如果需要任何其他信息,请告诉我,谢谢。
DBus
)。 - Zimano