【问题标题】:Automatically bind ePuck via bluetooth with bash or something else通过蓝牙与 bash 或其他东西自动绑定 ePuck
【发布时间】:2017-05-14 20:40:45
【问题描述】:

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

【问题讨论】:

  • 如何手动配对?
  • 首先打开 bluetoothctl 然后输入所有命令和 pin ..就像在 EOF 中的 echo -e 语句或上面一样.. 手动它可以正常工作
  • 那不一样,估计有提示。您可能会发现 expect 很有用。
  • expect 似乎很有趣,但以前从未使用或知道它。我试试,谢谢

标签: linux bash bluetooth bluez


【解决方案1】:

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回答key,您可能还需要注册默认代理或外部代理管理器进行回复。

dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.bluez.AgentManager1.RegisterAgent

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2014-04-10
    相关资源
    最近更新 更多