Bluez 5未知连接标识符 [英] Bluez 5 Unknown Connection Identifier
问题描述
我有一个运行最新Raspbian的Raspberry Pi 3,并且我有 从5.23升级了bluez.至5.43.我正在尝试连接到BLE 每隔2秒发布一次的设备.我写了一些基于 在gatttool上尝试连接到这些设备.我碰到了 LE连接请求在2秒后被取消.因此,我收到状态为0x02(未知连接标识符)的LE连接完成消息
I have a Raspberry Pi 3 running the latest Raspbian, and I have upgraded bluez from 5.23. to 5.43. I am attempting to connect to BLE devices that advertise at 2 second interval. I wrote some code based on gatttool and attempted to connect to these devices. I run into the LE connect request being cancelled after 2 seconds. Thus I get a LE Connection Complete messages with a status of 0x02 (Unknown Connection Identifier)
根据我的研究,我在大约15个月前的档案中遇到了这个问题,
From my research I ran across this from about 15 months ago in the archives,
https://www.spinics.net/lists/linux-bluetooth/msg65434.html
但是,在跟踪线程之后,我没有看到是否找到解决方法.
However after following the threads, I did not see if a resolution was found.
我已经用我的代码,gatttool实用程序以及使用了 蓝牙.我在列出的btmon中看到了相同类型的活动 下方:
I have ran tests with my code, the gatttool utility and well as using bluetoothctl. I see the same type of activity in btmon that is listed below:
HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7 [hci0] 21:45:51.917070
Type: Passive (0x00)
Interval: 60.000 msec (0x0060)
Window: 30.000 msec (0x0030)
Own address type: Public (0x00)
Filter policy: Ignore not in white list (0x01)
> HCI Event: Command Complete (0x0e) plen 4 [hci0] 21:45:51.917819
LE Set Scan Parameters (0x08|0x000b) ncmd 1
Status: Success (0x00)
HCI Event: Command Complete (0x0e) plen 4 [hci0] 21:45:51.918357
LE Set Scan Enable (0x08|0x000c) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 27 [hci0] 21:45:52.597503
LE Advertising Report (0x02)
Num reports: 1
Event type: Connectable undirected - ADV_IND (0x00)
Address type: Random (0x01)
Address: D3:67:2D:D1:46:46 (Static)
Data length: 15
Flags: 0x06
LE General Discoverable Mode
BR/EDR Not Supported
Company: FedEx Services (321)
Data: 070a111080d28004
RSSI: -63 dBm (0xc1)
HCI Event: Command Complete (0x0e) plen 4 [hci0] 21:45:52.599626
LE Set Scan Enable (0x08|0x000c) ncmd 1
Status: Success (0x00)
HCI Event: Command Status (0x0f) plen 4 [hci0] 21:45:52.600508
LE Create Connection (0x08|0x000d) ncmd 1
Status: Success (0x00)
HCI Event: Command Complete (0x0e) plen 4 [hci0] 21:45:54.684146
LE Create Connection Cancel (0x08|0x000e) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19 [hci0] 21:45:54.684361
LE Connection Complete (0x01)
Status: Unknown Connection Identifier (0x02)
Handle: 64
Role: Master (0x00)
Peer address type: Random (0x01)
Peer address: D3:67:2D:D1:46:46 (Static)
Connection interval: 67.50 msec (0x0036)
Connection latency: 0.00 msec (0x0000)
Supervision timeout: 420 msec (0x002a)
Master clock accuracy: 0x00
@ Connect Failed: D3:67:2D:D1:46:46 (2) status 0x02
看起来在代码中某个地方有2秒的超时,也许在内核方面.
It looks like there is a 2 second timeout somewhere in the code, perhaps kernel side.
要注意的一件事是,如果我使用hcitool进行连接,则可以连接 大部分时间.我知道这不是L2CAP层,但是我可以 看到我能够连接.
One thing to note is if I use hcitool to connect, I am able to connect most all of the time. I know this is not the L2CAP layer, but I can see that I am able to connect.
此外,如果我将BLE设备的广告间隔更改为1秒.我可以很好地连接. (原因是2秒钟的广告间隔可以节省电量)
Also, if I change the advertising interval of the BLE devices to 1 second. I can connect just fine. (Reason for 2 sec advertising interval is power savings)
最近有没有人遇到过这个问题,如果有的话,是否有解决方案?
Has anyone recently ran into this issue, and if so has there been any resolution?
谢谢
推荐答案
存在相同的问题.您已经注意到,将广告间隔从10s减少到0.5s确实可以解决此问题.我也需要更长的时间间隔以节省电池.我知道使用旧版本的Raspbian(2016-03-18-raspbian-jessie内核4.1.19-v7 +#858 SMP,bluez 5.23)可以正常工作,但是,我还没有找到一个更新的版本.
Having the same issue. Reducing the advertisement interval, as you've noted, from 10s to 0.5s does fix the issue. I, also, need a longer interval to conserve battery. I know that using an older build of Raspbian ( 2016-03-18-raspbian-jessie kernel 4.1.19-v7+ #858 SMP, bluez 5.23 ) works fine, however, I have yet to get a newer build to work.
更新 发现该帖子后: https://www.spinics.net/lists/linux -bluetooth/msg67800.html 我在include/net/bluetooth/hci.h中更改了以下值:
UPDATE After discovering this post: https://www.spinics.net/lists/linux-bluetooth/msg67800.html I changed the following values in include/net/bluetooth/hci.h:
#define HCI_LE_CONN_TIMEOUT msecs_to_jiffies(22000) /* 22 seconds WAS 2 seconds */
#define HCI_LE_AUTOCONN_TIMEOUT msecs_to_jiffies(22000) /* 22 seconds WAS 2 seconds */
已重新编译,并且所有设备现在都以10.24秒的广播间隔从我的设备上以最新版本的Raspbian内核4.4.50和bluez 5.45进行广播.希望这会有所帮助.
recompiled, and all is working now with a 10.24 second broadcast interval from my device on the latest version of Raspbian kernel 4.4.50 with bluez 5.45. Hope this helps.
这篇关于Bluez 5未知连接标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!