From 77cdd56641c04e01a194c5cbdbaa44890d5145e9 Mon Sep 17 00:00:00 2001 From: James Smith Date: Wed, 13 May 2026 21:15:24 +0100 Subject: [PATCH] debug(meshcore): enable BLE debug mode and disconnect before connect - Enable debug=True on MeshCore.create_ble() to surface verbose logs - Disconnect any existing BlueZ connection before bleak connects to avoid conflicts from prior bluetoothctl/pairing sessions Co-Authored-By: Claude Sonnet 4.6 --- utils/meshcore_client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils/meshcore_client.py b/utils/meshcore_client.py index 3cf0a64..3e1b99e 100644 --- a/utils/meshcore_client.py +++ b/utils/meshcore_client.py @@ -107,7 +107,20 @@ class AsyncWorker: self._mc = await MeshCore.create_tcp(host=cfg.host, port=cfg.port, debug=False) transport, device = "tcp", f"{cfg.host}:{cfg.port}" elif isinstance(cfg, BLEConfig): - self._mc = await MeshCore.create_ble(address=cfg.device_address, debug=False) + # Disconnect any existing BlueZ connection so bleak gets a clean slate + if cfg.device_address: + try: + import subprocess + + subprocess.run( + ["bluetoothctl", "disconnect", cfg.device_address], + timeout=3, + capture_output=True, + ) + await asyncio.sleep(1.0) + except Exception: + pass + self._mc = await MeshCore.create_ble(address=cfg.device_address, debug=True) transport, device = "ble", cfg.device_address or "auto" else: raise RuntimeError(f"Unknown connection config type: {type(cfg)}")