【发布时间】:2016-09-24 17:05:09
【问题描述】:
我正在编写一个 Python 脚本来搜索蓝牙设备并使用 RFCOMM 连接它们。该设备具有密码/密码。我正在使用 PyBlueZ,据我所知,这个库无法处理密码/密码连接 (Python PyBluez connecting to passkey protected device)。
我能够发现这些设备并检索它们的名称和地址:
nearby_devices = bluetooth.discover_devices(duration=4,lookup_names=True,
flush_cache=True, lookup_class=False)
但如果尝试使用以下方式连接到特定设备:
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.connect((addr,port))
我收到一个错误'Device or resource busy (16)'。
我使用 hcitool 和 bluetooth-agent 尝试了一些 bash 命令,但我需要以编程方式进行连接。我能够使用此处描述的步骤连接到我的设备:How to pair a bluetooth device from command line on Linux。
我想询问是否有人使用 Python 使用密码/密码连接到蓝牙设备。我正在考虑使用subprocess.call() 在 Python 中使用 bash 命令,但我不确定这是否是个好主意。
感谢您的帮助。
【问题讨论】:
标签: python linux bluetooth pybluez