PyBluez找不到跟踪标签devi

2024-05-23 21:14:55 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这是我通过蓝牙CTL得到的:

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设备是一个便宜的小瓷砖式的中国“找到我的钥匙”型蓝牙设备,这是我正在寻找的。这两个HTC可能是我们的HTV Vive灯塔。

使用Python2,跳出所有的障碍来安装pybluez和gattlib,以及所有这些,使用所附的代码,我得到:

^{pr2}$

DESKTOP-NUBAQ2D是一款内置蓝牙的台式PC,通过BT与HTC Vive灯塔进行通话

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

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

有些建议要改变服务。发现(2) 到一个更高的数字,表示扫描时间是2秒,但不管是2秒还是20秒,它都会立即停止。。。所以也许发现(20)工作不正常?

是否有一个详细的模式或其他一些选项我可以尝试,或者有时我丢失了(可能需要为rpizero调整配置)。。好像它没有指向正确的设备?)

我在编程方面很有经验,但对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))

Tags: namenewscandeviceacbluetoothdevicesprint