From 4ebe75de5983fe993def08b00793fb04c0cd4aad Mon Sep 17 00:00:00 2001 From: Patryk Koscik Date: Mon, 20 Oct 2025 21:47:26 +0200 Subject: [PATCH] fix: ble: bluez: force manual MTU negotiation --- catprinter/ble.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/catprinter/ble.py b/catprinter/ble.py index e8e6af5..c3ae9d0 100644 --- a/catprinter/ble.py +++ b/catprinter/ble.py @@ -6,6 +6,7 @@ from bleak import BleakClient, BleakScanner from bleak.backends.scanner import AdvertisementData from bleak.backends.device import BLEDevice +from bleak.backends.bluezdbus.client import BleakClientBlueZDBus from catprinter import logger # For some reason, bleak reports the 0xaf30 service on my macOS, while it reports @@ -96,6 +97,11 @@ async def run_ble(data, device: Optional[str]): return logger.info(f"⏳ Connecting to {address}...") async with BleakClient(address) as client: + # XXX: BlueZ incorrectly reports a fixed MTU of 23; force MTU negotiation manually. + # https://bleak.readthedocs.io/en/latest/api/client.html#bleak.BleakClient.mtu_size + if isinstance(client, BleakClientBlueZDBus): + await client._acquire_mtu() + logger.info(f"✅ Connected: {client.is_connected}; MTU: {client.mtu_size}") chunk_size = client.mtu_size - 3 event = asyncio.Event()