【问题标题】:Can´t seem to make Bluetooth agent work in Raspberry Pi似乎无法让蓝牙代理在 Raspberry Pi 中工作
【发布时间】:2021-12-05 06:45:15
【问题描述】:

所以,我要做的是创建一个 Python 脚本,它允许我通过蓝牙将安卓手机与树莓派连接起来​​。如果我手动执行此操作(在命令行中编写指令),它工作得很好,我可以搜索、配对和连接范围内的任何设备。

但是,如果我通过脚本执行此操作,当我尝试激活代理时会弹出消息没有注册代理,这意味着我将无法配对任何设备,因为这是使树莓派和安卓手机显示的确认码一致的工具。

我使用的代码有点像这样。

 import os
 import sys
 import time

 os.system('sudo systemctl enable bluetooth')
 os.system('sudo systemctl start bluetooth')
 os.system('bluetoothctl discoverable on')
 os.system('bluetoothctl agent on')
 os.system('bluetoothctl default-agent')
 os.system('bluetoothctl pairable on')
 os.system('timeout 30 bluetoothctl scan on')
 os.system('bluetoothctl pair XX:XX:XX:XX:XX:XX')

任何帮助或想法将不胜感激

【问题讨论】:

    标签: python-3.x bluetooth raspberry-pi


    【解决方案1】:

    bluetoothctl 不打算以这种方式使用。要从 Python BlueZ 访问 BlueZ 功能,请提供一组 D-Bus API,这些 API 记录在: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

    他们有关于如何使用这些 API 的 Python 示例:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test

    【讨论】:

    • 谢谢大佬,我去看看
    猜你喜欢
    • 1970-01-01
    • 2015-03-27
    • 2011-11-30
    • 2015-09-20
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多