Raspbian 上的低功耗蓝牙 [英] Bluetooth LE on Raspbian
问题描述
我从源代码安装了 bluez-5.15,配置如下:
I installed bluez-5.15 from source with the following configuration:
$ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc
--localstatedir=/var --libexecdir=/lib --disable-systemd
然后我不得不手动将 gatttool 复制到/usr/local/bin 目录中
Then I had to copy gatttool manually into the /usr/local/bin dir
$ sudo cp attrib/gatttool /usr/local/bin/
我重新启动了 Raspberry Pi 并尝试了以下操作以连接到我的 BLE 设备:
I rebooted the Raspberry Pi and tried the following to connect to my BLE device:
$ 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 连接:
So then I tried to connect with 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]>
我在这里遗漏了什么 - 这是配置问题吗?错误是什么意思?
What am I missing here - is this a configuration issue? What do the errors mean?
推荐答案
首先,我和一位同事讨论了我的配置,对于 Raspbian(或者更具体地说,Debian)他推荐了以下配置设置:
First off, I spoke with a colleague about my configuration and for Raspbian (or more specifically, Debian) he recommended the following configuration settings:
./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 地址标志设置为随机".见下文:
Afterward, upon further inspection, here is how I was able to successfully connect. So what was happening was that the device I was trying to connect to (an NRF-based BLE device) required the LE address flag to be set to 'random'. See below:
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
哈扎!此外,可能需要将安全级别设置为低于高:
Huzzah! Also, there may be a need to set the security level to something lower than high:
[EA:FB:B5:CE:B0:13][LE]> sec-level medium
这篇关于Raspbian 上的低功耗蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!