通过蓝牙与bash或其他东西自动绑定ePuck

时间:2017-05-14 20:40:46

标签: linux bash bluetooth bluez

我正在尝试使用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太快退出了。

1 个答案:

答案 0 :(得分:0)

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
相关问题