首页 > 解决方案 > PyBluez 找不到跟踪标签设备

问题描述

bluetoothctl 看到 ITAG 设备,但 python 和 pybluez 没有在 Raspberry Pi Zero W 上

这是我通过 bluetoothctl 得到的:

pi@rpitouch:~ $ sudo bluetoothctl
[NEW] Controller B8:27:EB:6A:C0:8F rpitouch [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:6A:C0:8F Discovering: yes
[NEW] Device AC:37:43:F6:91:BF HTC BS BFED75
[NEW] Device AC:37:43:F6:13:98 HTC BS 9885EC
[CHG] Device AC:37:43:F6:91:BF RSSI: -66
[CHG] Device AC:37:43:F6:91:BF TxPower: 4
[NEW] Device FC:58:FA:A3:3A:76 ITAG
[CHG] Device AC:37:43:F6:13:98 RSSI: -61

ITAG设备是一款便宜的小Tile风格的中文“找我的钥匙”类型的蓝牙设备,这正是我想要找到的。这两个 HTC 可能是我们的 HTV Vive 灯塔。

使用 Python 2 并跳过所有的障碍来安装 pybluez 和 gattlib 以及所有这些,使用附加的代码,我得到:

pi@rpitouch:~ $ sudo python blue.py
found 1 bluetooth devices
 F8:34:41:8B:D0:25 - DESKTOP-NUBAQ2D
found 0 btle devices

DESKTOP-NUBAQ2D 是一款台式电脑,内置蓝牙,可通过 BT 与 HTC Vive 灯塔通信。

我还尝试了 BeaconService 选项,结果也为零。

如果 bluetoothctl 和 pybluez 找到不同的设备,它们看起来会扫描不同的东西。就像 bluetoothctl 正在寻找设备而 pybluez 正在寻找主机?

一些建议是将 service.discover(2) 更改为更高的数字,表明这是 2 秒的扫描时间,但无论是 2 秒还是 20 秒,它都会立即停止......所以也许那个 discover(20) 不能正常工作?

是否有详细模式或我可以尝试的其他一些选项,或者有时我会丢失(可能需要针对 RPi 零调整配置......就像它没有指向正确的设备一样?)

我在编程方面经验丰富,但在 python 和 linux 生态系统的这个角落相当绿色,所以具体要检查哪些文件或东西是值得赞赏的......或者至少有足够的关键字可以让我在谷歌上搜索细节。

谢谢!

# https://github.com/pybluez/pybluez
import bluetooth

nearby_devices = bluetooth.discover_devices(lookup_names=True)
print("found %d bluetooth devices" % len(nearby_devices))

for addr, name in nearby_devices:
    print(" %s - %s" % (addr, name))

#bluetooth low energy scan
from bluetooth.ble import DiscoveryService

service = DiscoveryService()
print("Starting scan")
devices = service.discover(20)

print("found %d btle devices" % len(devices))

for address, name in devices.items():
    print("name: {}, address: {}".format(name, address))

标签: pythonbluetoothraspberry-pipybluezraspberry-pi-zero

解决方案


推荐阅读