我想使用任何移动电话通过蓝牙经典与串行端口协议(SPP)连接到IoT设备。IoT设备没有屏幕和键盘,只要连接的手机知道一个秘密的PIN码,它就会自动接受连接(即,我不想每次新手机尝试连接时都被强制ssh到IoT设备来设置配对)。
以下是我到目前为止在IoT设备上运行的命令:
# Make the device discoverable:
hciconfig hci0 piscan
# Register SPP:
sdptool add --channel=22 SP
# Start rfcomm:
rfcomm -r watch /dev/rfcomm0 22
不幸的是,我找不到任何方法来设置PIN,当我尝试连接手机时,配对失败。此外,该设备只能在短时间间隔内被发现。
如何配置IoT设备的蓝牙堆栈(运行最新的Bluez)以与任何知道给定PIN码的电话自动配对,以及如何使发现周期永恒不变?
发布于 2017-03-28 16:36:03
您可以运行实现BlueZ DBus API的应用程序。I重新命令BlueZ >= 5.42。使用代理接口并实现您自己的PIN代码。注册您的代理后,bluez将自动呼叫并在要求配对时使用您自己的代理。
此外,您还可以通过org.bluez.Adapter1接口通过DBus将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/ (在底部读取)
发布于 2021-05-10 02:23:42
如果有人碰巧遇到这个问题,要直接从bash中使用(大部分) BlueZ "BT管理套接字“bash,请尝试:
btmgmt --help
btmgmt add-device
、btmgmt find
、btmgmt discov
等。
https://stackoverflow.com/questions/42135297
复制相似问题