【发布时间】:2016-08-05 02:15:00
【问题描述】:
我可以使用带有 --duplicates 标志的 hcitool lescan 从附近的两个 BLE 设备捕获定期 LE 广告报告(接近信标):
$ sudo hcitool lescan --duplicates
LE Scan ...
C8:0F:10:29:4D:98 MI1S
C8:0F:10:29:4E:75 MI1S
C8:0F:10:29:4E:75 MI1S
C8:0F:10:29:4D:98 MI1S
C8:0F:10:29:4E:75 MI1S
C8:0F:10:29:4D:98 MI1S
<snip>
这是再次扫描,添加了时间戳以显示周期性:
$ sudo stdbuf -i0 -o0 -e0 hcitool lescan --duplicates | perl -nle 'print scalar(localtime), " ", $_'
Wed Apr 13 13:46:45 2016 LE Scan ...
Wed Apr 13 13:46:46 2016 C8:0F:10:29:4E:75 MI1S
Wed Apr 13 13:46:47 2016 C8:0F:10:29:4D:98 MI1S
Wed Apr 13 13:46:48 2016 C8:0F:10:29:4E:75 MI1S
Wed Apr 13 13:46:48 2016 C8:0F:10:29:4D:98 MI1S
Wed Apr 13 13:46:50 2016 C8:0F:10:29:4D:98 MI1S
Wed Apr 13 13:46:52 2016 C8:0F:10:29:4E:75 MI1S
<snip>
在上周(2016 年 4 月)的嵌入式 Linux 会议和物联网峰会上,一位从事 BlueZ 堆栈工作的演讲者表示不再使用 hcitool,而是改用 bluetoothctl。
我今天试过了,但它只显示设备的第一个 LE 广告报告(就像 hcitool 没有 --duplicates 选项一样):
$ sudo bluetoothctl
[NEW] Controller 5C:F3:70:62:68:28 BlueZ 5.38 [default]
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 5C:F3:70:62:68:28 Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller 5C:F3:70:62:68:28 Discovering: yes
[CHG] Device C8:0F:10:29:4E:75 RSSI: -72
[CHG] Device C8:0F:10:29:4D:98 RSSI: -65
[bluetooth]# devices
Device C8:0F:10:29:4D:98 MI1S
Device C8:0F:10:29:4E:75 MI1S
您如何使用 bluetoothctl 从同一设备捕获重复的 LE 广告报告,就像 hcitool 使用 --duplicates 选项一样?
【问题讨论】:
-
我很想知道为什么建议改用 bluetoothctl,以及您是否能够使其正常工作。
-
因为
bluetoothctl通过 DBus 与蓝牙守护进程对话,而不是像hcitool那样直接与硬件对话。而且 hcitool 现在通常会失败,因为 BT 守护进程具有独占访问权限。
标签: bluetooth linux-kernel bluetooth-lowenergy embedded-linux