在Linux上设置蓝牙自动配对

Jon*_*ark 24 bluetooth rfcomm bluez

我想使用任何手机通过蓝牙Classic与串行端口协议(SPP)连接到物联网设备.物联网设备没有屏幕,没有键盘,只要连接电话知道一个秘密密码,就应该自动接受连接(即,我不想强​​迫每次都进入物联网设备进行配对一部新手机试图连接).

这些是我到目前为止在物联网设备上运行的命令:

# Make the device discoverable:
hciconfig hci0 piscan

# Register SPP:
sdptool add --channel=22 SP

# Start rfcomm:
rfcomm -r watch /dev/rfcomm0 22
Run Code Online (Sandbox Code Playgroud)

不幸的是,我找不到任何设置PIN的方法,当我尝试连接手机时,配对失败了.此外,该设备只能在短时间内被发现.

如何配置物联网设备的蓝牙堆栈(运行最近的Bluez)以与任何知道给定PIN的电话自动配对,以及如何使发现期间永恒?

Fra*_*ont 0

您可以运行实现 BlueZ DBus API 的应用程序。我推荐 BlueZ >= 5.42。使用代理界面并实施您自己的 PIN 码。注册您的代理后,当要求配对时,bluez 将自动呼叫并使用您自己的代理。

此外,您可以通过 DBus 的 org.bluez.Adapter1 接口将 DiscoverableTimeout 设置为 0。

“值为零意味着超时被禁用,它将永远保持在可发现/有限模式。”

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt(dbus适配器对象文档) https://git.kernel.org/pub/scm/bluetooth /bluez.git/tree/doc/agent-api.txt(dbus 代理对象文档) https://kernel.googlesource.com/pub/scm/bluetooth/bluez/+/5.44/test/simple-agent(示例) http://www.bluez.org/bluez-5-api-introduction-and-porting-guide/(在底部阅读)