Raspbian上的蓝牙LE

我使用以下configuration从源代码安装了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/ 

我重新启动了树莓派,并尝试以下连接到我的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 

那么我试着用gattool连接:

 $ 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]> 

我在这里错过了什么 – 这是一个configuration问题? 这些错误是什么意思?

首先,我和一位同事就我的配置和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 

从我的经验与蓝色5.15

  1. 确保您没有连接到BLE设备(使用hcitool con进行检查)。
  2. 不要运行hcitool lecc
  3. 像你的问题一样启动gattool
  4. gatttool运行连接命令。 如果该命令挂起,然后按设备上的按钮(即连接到SensorTag时有时需要)。

我相信Bluez的早期版本需要hcitool lecc步骤,但现在不是这样了。