Skip to content

Commit 4ebe75d

Browse files
committed
fix: ble: bluez: force manual MTU negotiation
1 parent 9ec21a8 commit 4ebe75d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

catprinter/ble.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from bleak import BleakClient, BleakScanner
77
from bleak.backends.scanner import AdvertisementData
88
from bleak.backends.device import BLEDevice
9+
from bleak.backends.bluezdbus.client import BleakClientBlueZDBus
910
from catprinter import logger
1011

1112
# 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]):
9697
return
9798
logger.info(f"⏳ Connecting to {address}...")
9899
async with BleakClient(address) as client:
100+
# XXX: BlueZ incorrectly reports a fixed MTU of 23; force MTU negotiation manually.
101+
# https://bleak.readthedocs.io/en/latest/api/client.html#bleak.BleakClient.mtu_size
102+
if isinstance(client, BleakClientBlueZDBus):
103+
await client._acquire_mtu()
104+
99105
logger.info(f"✅ Connected: {client.is_connected}; MTU: {client.mtu_size}")
100106
chunk_size = client.mtu_size - 3
101107
event = asyncio.Event()

0 commit comments

Comments
 (0)