4

我使用以下配置从源代码安装了 bluez-5.15:

$ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc \
--localstatedir=/var --libexecdir=/lib --disable-systemd

然后我不得不手动将 gatttool 复制到 /usr/local/bin 目录中

$ sudo cp attrib/gatttool /usr/local/bin/

我重新启动了 Raspberry Pi 并尝试了以下连接到我的 BLE 设备:

$ sudo hciconfig hci0 up

$ sudo hcitool lescan
LE Scan ...  
EA:FB:B5:CE:B0:13 DfuTarg

$ sudo hcitool lewladd EA:FB:B5:CE:B0:13

$ sudo hcitool lecc EA:FB:B5:CE:B0:13
Could not create connection: Input/output error

于是我尝试连接 gatttool:

$ gatttool -b EA:FB:B5:CE:B0:13 --interactive
[EA:FB:B5:CE:B0:13][LE]> connect
Attempting to connect to EA:FB:B5:CE:B0:13
Error: connect error: Device or resource busy (16)
[EA:FB:B5:CE:B0:13][LE]>

我在这里缺少什么-这是配置问题吗?这些错误是什么意思?

4

2 回答 2

11

首先,我与一位同事讨论了我的配置,对于 Raspbian(或更具体地说,Debian),他推荐了以下配置设置:

./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-library --with-systemdsystemunitdir=/lib/systemd/system --with-systemduserunitdir=/usr/lib/systemd

之后,经过进一步检查,这就是我成功连接的方式。所以发生的事情是我试图连接的设备(基于 NRF 的 BLE 设备)需要将 LE 地址标志设置为“随机”。见下文:

gatttool -t random -b EA:FB:B5:CE:B0:13 -I

然后结果:

[EA:FB:B5:CE:B0:13][LE]> connect
Attempting to connect to EA:FB:B5:CE:B0:13
Connection successful
[EA:FB:B5:CE:B0:13][LE]> characteristics
handle: 0x0002, char properties: 0x0a, char value handle: 0x0003, uuid: 00002a00
-0000-1000-8000-00805f9b34fb

嘘!此外,可能需要将安全级别设置为低于高的级别:

[EA:FB:B5:CE:B0:13][LE]> sec-level medium
于 2014-03-11T00:01:18.627 回答
5

From my experience with Bluez 5.15

  1. Ensure you have no connections to the BLE device (check with hcitool con).
  2. Do not run hcitool lecc.
  3. Start gatttool like in your question.
  4. In gatttool run connect command. If the command hangs, then press button on the device (i.e. sometimes needed when connecting to SensorTag).

I believe earlier versions of Bluez required hcitool lecc step, but it is not the case anymore.

于 2014-03-09T23:46:38.210 回答