【问题标题】:BlueZ stopped working (it doesn't discover any SDP service)BlueZ 停止工作(它没有发现任何 SDP 服务)
【发布时间】:2020-12-09 13:02:06
【问题描述】:

我正在使用最新的 Bluez 版本 5.53-0ubuntu3 PyBluez,直到昨天一切正常 这个 python 代码发现服务很好

import bluetooth
mac = "FF:A0:AB:21:20:F4"
print(bluetooth.find_service(address=mac)

但是今天这个 python 代码开始给我空列表而不是通常的服务,所以我调试了它并且真的很困惑,因为我认为我已经破坏了一些东西,而且我的三星 Galaxy S10+ 不能只是停止发送蓝牙服务(我确认它仍然通过在另一部手机上使用蓝牙扫描仪应用程序广播蓝牙服务并且它仍然广播服务)

然后我尝试使用 sdptool 浏览服务 sudo sdptool browse FF:A0:AB:21:20:F4 它给了我 Failed to connect to SDP server on FF:A0:AB:21:20:F4: Operation now in progress

然后我尝试使用浏览本地服务,一开始它给了

Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory

但我设法使用这个 anwser 解决了这个问题:https://stackoverflow.com/a/33141030/14105014

然后它至少显示了本地服务,但它仍然没有显示远程蓝牙服务

不确定我有 RT3290 芯片组是否重要,我使用以下代码安装了它的驱动程序:https://askubuntu.com/a/1021231 它一直工作到昨天

希望有人知道为什么会发生这种情况以及是否可以解决?

感谢您的回答和最诚挚的问候

【问题讨论】:

    标签: ubuntu bluetooth bluez pybluez


    【解决方案1】:

    BlueZ 开发人员已将许多工具标记为deprecated。我的理解是您现在使用--compat 开关启动bluetoothd。看着man page,这个

    提供已弃用的命令行界面

    解决方案是改用 BlueZ 目前支持的工作方式。这意味着使用 D-Bus API,记录在:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

    Python 有许多不同的 D-Bus 绑定。下面是pydbus的示例

    这会扫描附近的设备 20 秒,然后打印出所有支持 A2DP 配置文件的设备

    import pydbus
    from gi.repository import GLib
    
    discovery_time = 20
    
    bus = pydbus.SystemBus()
    mainloop = GLib.MainLoop()
    
    # Connect to the DBus api for the Bluetooth adapter
    adapter = bus.get('org.bluez', '/org/bluez/hci0')
    
    def end_discovery():
        """Handler for end of discovery"""
        mainloop.quit()
        adapter.StopDiscovery()
    
    # Run discovery
    adapter.StartDiscovery()
    GLib.timeout_add_seconds(discovery_time, end_discovery)
    print('Finding nearby devices...')
    mainloop.run()
    
    # Iterate around the devices to find audio devices
    mngr = bus.get('org.bluez', '/')
    mng_objs = mngr.GetManagedObjects()
    
    for path in mng_objs:
        uuids = mng_objs[path].get('org.bluez.Device1', {}).get('UUIDs', [])
        # print(path, uuids)
        for uuid in uuids:
            # Service discovery UUIDs
            # https://www.bluetooth.com/specifications/assigned-numbers/service-discovery/
            # AudioSink - 0x110B - Advanced Audio Distribution Profile (A2DP)
            if uuid.startswith('0000110b'):
                print(mng_objs[path].get('org.bluez.Device1', {}).get('Name'),
                      mng_objs[path].get('org.bluez.Device1', {}).get('Address'))
    

    【讨论】:

    • 我重新安装了 ubuntu 20.04 并再次安装了蓝牙驱动程序,现在奇怪的是现在连设置都找不到任何蓝牙设备了(设备处于发现模式)所以我真的不知道现在该尝试什么,我也尝试过您的示例并安装了 pydbus,但它没有找到单个设备,所以我开始怀疑它可能是硬件故障??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    相关资源
    最近更新 更多