linux - 通过蓝牙与 bash 或其他东西自动绑定(bind) ePuck

标签 linux bash bluetooth bluez

我正在尝试使用 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/

相关文章:

linux - find xargs mac 更改文件扩展名

bash - 如何使用 Go 获取 shell 脚本?

swift - AppDelegate中applicationDidEnterBackground时调用ViewController

ios - 蓝牙 HM-10 PIN 连接,身份验证/安全

linux - 为什么 shell 中的文件名后面要加上\n?

linux - 在本地桌面计算机上替换 someaddress.com

linux - 如何协调两个linux进程以两步锁步计划运行?

linux - 如何在 Bluez 4 中禁用拨号网络服务?

c - 使用 system() 打开 2 个终端并选择默认输出

Linux open() 文件描述符