我正在尝试使用bash脚本自动绑定/配对(而不是连接) ePuck机器人和Linux。我研究了很多关于bluetoothctl的知识,但没有发现任何真正有用的东西。问题是ePuck使用固定的引脚,所以每次我想要绑定/配对它时,我都必须手动输入引脚(每次完成工作后,我都会移除/取消配对ePuck,这就是为什么我每次都必须重新输入引脚)。
它不一定是bashscript。我听说我也可以用python来实现。但是我在Linux和编程方面是个新手,所以我才问这个问题。
这就是我到目前为止所拥有的(2228是ePuck的引脚):
#!/bin/bash
##first tried with EOF
bluetoothctl <<EOF
power on
agnet on
scan on
pair 10:00:E8:AD:77:31
2228
EOF
##then with echo -e
echo -e 'power on\nagent on\nscan on\npair 10:00:E8:AD:77:31\n2228\n' | bluetoothctl
我不知道如何确切地使用EOF或echo -e,但我在互联网上有这个解决方案。在这两种方式中,都没有进行配对。看起来bluetoothctl退出得太快了。
发布于 2017-05-15 12:20:43
bluetoothctl接口对于您的用例可能不太方便。您可以尝试以下dbus-send命令(未经过测试,但这应该可以工作)。
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set string:"org.bluez.Adapter1" string:"Powered" variant:boolean:true
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set string:"org.bluez.Adapter1" string:"Discoverable" variant:boolean:true
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter1.StartDiscovery
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_10_00_E8_AD_77_31 org.freedesktop.DBus.Properties.Set string:"org.bluez.Device1" string:"Trusted" variant:boolean:true
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_10_00_E8_AD_77_31 org.bluez.Device1.Pair
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_10_00_E8_AD_77_31 org.bluez.Device1.Connect
如果蓝牙守护程序服务在bluetooth.service中是可激活的,则无需启动该服务。
要通过dbus回答密钥,您可能还需要注册默认代理或外部代理管理器进行回复。
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.bluez.AgentManager1.RegisterAgent
https://stackoverflow.com/questions/43968600
复制相似问题