From 7d537998ca52fd7ce611a4ac30fcdcdda23d5e5e Mon Sep 17 00:00:00 2001 From: James Smith Date: Wed, 13 May 2026 20:49:44 +0100 Subject: [PATCH] fix(meshcore): revert wrong scan_ble_sync route call, fix scan without worker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Revert route to scan_ble() — scan_ble_sync() lives on AsyncWorker, not MeshcoreClient; the 500 was caused by our previous fix - MeshcoreClient.scan_ble() now runs a one-shot asyncio scan when no worker is active, so Scan works before Connect is pressed Co-Authored-By: Claude Sonnet 4.6 --- routes/meshcore.py | 2 +- utils/meshcore.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/routes/meshcore.py b/routes/meshcore.py index 4990afd..57f6fca 100644 --- a/routes/meshcore.py +++ b/routes/meshcore.py @@ -93,7 +93,7 @@ def ports(): def ble_scan(): if not is_meshcore_available(): return api_error("meshcore not installed", 503) - devices = _client().scan_ble_sync() + devices = _client().scan_ble() return jsonify({"devices": devices}) diff --git a/utils/meshcore.py b/utils/meshcore.py index 8b86a40..7520095 100644 --- a/utils/meshcore.py +++ b/utils/meshcore.py @@ -413,10 +413,19 @@ class MeshcoreClient: self._worker.request_traceroute(node_id) def scan_ble(self) -> list[dict]: - """Scan for BLE MeshCore devices; returns list of found device dicts.""" + """Scan for BLE MeshCore devices; works with or without an active connection.""" if self._worker: return self._worker.scan_ble_sync() - return [] + # No worker yet — run a one-shot scan directly + import asyncio + + from utils.meshcore_client import _scan_ble + + try: + return asyncio.run(_scan_ble()) + except Exception as exc: + logger.warning("BLE scan failed: %s", exc) + return [] _client: MeshcoreClient | None = None