BlueZ client._acquire_mtu() raises RuntimeError on many devices
See original GitHub issueMost 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:
- Created a year ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
_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 newmax_write_without_response_size
property.Closing since there isn’t anything else to do here.
See #738.