question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BlueZ client._acquire_mtu() raises RuntimeError on many devices

See original GitHub issue

Most test devices I have result in a RuntimeError from StopIteration because there are no write without response chars on the device. I’m able to get the MTU of the device with this proof of concept

            from bleak.backends.bluezdbus.manager import get_global_bluez_manager
            from bleak.backends.bluezdbus import defs
            logger.debug("%s: Acquiring MTU from BlueZ",name)
            await client.get_services()

            manager = await get_global_bluez_manager()
            device_path = client._device_path
            mtu: int | None = None
            for service_path, service_ifaces in manager._properties.items():
                if (
                    not service_path.startswith(device_path)
                    or defs.GATT_CHARACTERISTIC_INTERFACE not in service_ifaces
                ):
                    continue
                if "MTU" in service_ifaces[defs.GATT_CHARACTERISTIC_INTERFACE]:
                    mtu = service_ifaces[defs.GATT_CHARACTERISTIC_INTERFACE]["MTU"]
                    break
            if not mtu:
                try:
                    await client._acquire_mtu()
                    mtu = client._mtu_size
                except RuntimeError as ex:
                    logger.debug("%s: Failed to acquire MTU via _acquire_mtu: %s",name, ex)
                    pass
            if mtu:
                KNOWN_MTUS[device.address] = mtu
                client.set_known_mtu(mtu)
                logger.debug("%s: Acquired MTU from BlueZ %s", name, mtu)
            else:
                logger.debug("%s: No MTU from BlueZ", name)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dlechcommented, Aug 26, 2022

_acquire_mtu() is known to not work on all devices, it is only provided as a convenience for the cases where it does work and isn’t really possible to make it work in general. Other workarounds are possible like using a hard-coded value or using the new max_write_without_response_size property.

Closing since there isn’t anything else to do here.

1reaction
dlechcommented, Aug 8, 2022

See #738.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for bleak.backends.winrt.client - Read the Docs
``False`` will force the attribute database to be read from the remote device instead of using the OS cache. If omitted, the OS...
Read more >
BlueZ
Explains how to write code that acts as a Bluetooth LE Central device using Python, D-Bus and BlueZ, using practical exercises to compliment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found