0

I am using Bluez version 5.53-0ubuntu3 PyBluez latest and until yesterday everyhing worked fine this python code discovered services just fine

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

but today this python code started to give me empty list instead of the usual services, so I debugged it and was realy confused because I thougth I had broken something, and my Samsung Galaxy S10+ coudn't just stop sending bluetooth services (I confirmed that it still broadcasted bluetooth services by using Bluetooth Scanner app on another phone and it still broadcasted services)

then I tried to browse the services using sdptool sudo sdptool browse FF:A0:AB:21:20:F4 and it gave me Failed to connect to SDP server on FF:A0:AB:21:20:F4: Operation now in progress

then I tried using browsing local services and at first it gave

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

but I manage to solve that using this anwser: https://stackoverflow.com/a/33141030/14105014

and it then at least showed local services but it stil didn't show the remote bluetooth services

Not sure if it matters I have RT3290 chipset and I installed its drivers using this: https://askubuntu.com/a/1021231 and it worked until yesterday

Hope someone has any idea why this is happening and if it can be fixed?

Thanks for Anwsering and Best Regards

1 Answers1

0

There have been a number of tools that have been marked as deprecated by the BlueZ developers. My understanding is that you are launching bluetoothd with the --compat switch now. Looking at the man page, this

Provide deprecated command line interfaces

The solution would be to move to the currently supported way that BlueZ works. This means using the D-Bus API as documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

There are number of different D-Bus bindings for Python. Below is an example with pydbus

This scans for nearby devices for 20 seconds and then prints out all of the devices that support the A2DP profile

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'))
ukBaz
  • 6,985
  • 2
  • 8
  • 31
  • I reinstalled ubuntu 20.04 and installed the bluetooth driver again and now the weird thing is that now even settings doesn't find any bluetooth devices anymore (devices are in discovery mode) so I realy don't know what to try now, I also tried you sample and installed pydbus and it didn't find a single device, so I am starting to suspect it could be HW fault?? – TitovkaJeKapa Aug 20 '20 at 09:54