我正在研究一个Python脚本来搜索蓝牙设备并使用RFCOMM连接它们.此设备具有密码/密码.我正在使用PyBlueZ,据我所知,这个库无法处理Passkey/Password连接(Python PyBluez连接到passkey protected device).
我能够发现设备并检索它们的名称和地址:
nearby_devices = bluetooth.discover_devices(duration=4,lookup_names=True,
flush_cache=True, lookup_class=False)
Run Code Online (Sandbox Code Playgroud)
但如果尝试使用以下方法连接到特定设备:
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.connect((addr,port))
Run Code Online (Sandbox Code Playgroud)
我收到一个错误'Device or resource busy (16)'.
我使用hcitool和bluetooth-agent尝试了一些bash命令,但我需要以编程方式进行连接.我能够使用此处描述的步骤连接到我的设备:如何在Linux上从命令行配对蓝牙设备.
我想询问是否有人使用Python连接到使用Passkey/Password的蓝牙设备.我正在考虑在Python中使用bash命令subprocess.call(),但我不确定这是不是一个好主意.
谢谢你的帮助.