我正在尝试使用 bash 脚本将 ePuck 机器人与 Linux 自动绑定(bind)/配对(而不是连接)。我对 bluetoothctl 进行了很多研究,但没有发现任何有用的东西。问题是 ePuck 使用固定的 pin,所以我每次想绑定(bind)/配对时都必须手动输入 pin(我每次完成工作后都会删除/取消配对 ePuck,这就是为什么我必须重新输入 pin每次)。
它不应该是一个 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 退出得太快了。
最佳答案
bluetoothctl 接口(interface)可能不适合您的用例。您可以尝试以下 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 中是socket activatable,则不需要启动蓝牙守护服务。
要通过 dbus 回答 key ,您可能还需要注册默认代理或外部代理管理器来回复。
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.bluez.AgentManager1.RegisterAgent
关于linux - 通过蓝牙与 bash 或其他东西自动绑定(bind) ePuck,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43968600/