问题描述
我正在使用Bluez最新版本5.53-0ubuntu3 PyBluez,直到昨天一切正常 这个python代码发现的服务很好
import bluetooth
mac = "FF:A0:AB:21:20:F4"
print(bluetooth.find_service(address=mac)
但是今天,这个python代码开始为我提供空列表,而不是通常的服务,因此我对其进行了调试,并感到非常困惑,因为我认为我已经损坏了某些东西,而我的Samsung galaxy S10 +不能停止发送蓝牙服务(我确认它仍然通过在另一部手机上使用Bluetooth Scanner应用程序广播了蓝牙服务,并且仍在广播服务)
然后我尝试使用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
但是我设法使用以下答案来解决:https://stackoverflow.com/a/33141030/14105014
不确定是否有RT3290芯片组,并使用以下命令安装了其驱动程序:https://askubuntu.com/a/1021231 一直到昨天
希望有人知道为什么会发生这种情况以及它是否可以解决?
感谢大家的问候和问候
解决方法
BlueZ开发人员已将许多工具标记为deprecated。据我了解,您现在正在使用bluetoothd
开关启动--compat
。看着man page,这
提供不推荐使用的命令行界面
解决方案将转向BlueZ目前支持的工作方式。这意味着使用https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc
中记录的D-Bus APIPython有许多不同的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'))