我目前正在尝试在 Linux 板和微控制器之间实现 Just Works 配对。尝试配对时出现
org.bluez.Error.AuthenticationFailed
错误,在我的微控制器一侧显示 The confirm values in the numeric comparison protocol do not match.
看来 BlueZ 正在尝试启动数字比较配对,即使我的微控制器的 I/O 功能为 NoInput/NoOutput。
使用
bluetoothctl
从命令行配对时,不会发生这些问题,因此我的代码似乎有缺陷。我使用 dbus-python
与 BlueZ 进行通信。这就是我目前尝试配对的方式:
device_proxy = bus.get_object("org.bluez",device_path)
self.device_interface = dbus.Interface(device_proxy, "org.bluez.Device1")
try:
self.device_interface.Pair()
except dbus.exceptions.DBusException as e:
print(e.get_dbus_name())
print(e.get_dbus_message())
return bluetooth_constants.RESULT_ERR
else:
print("Pairing OK")
return bluetooth_constants.RESULT_OK
如何确保 BlueZ 使用 Just Works 配对而不是数字比较?
对于遇到此问题的任何其他人,我设法通过实现自定义代理来解决此问题。我查看了 BlueZ github 页面中的 simple_agent 示例 (bluez/test/simple-agent)。