From 6254440a2f62e01724c6dd1f235febc58addd167 Mon Sep 17 00:00:00 2001 From: Florent Date: Mon, 16 Feb 2026 14:09:14 -0400 Subject: [PATCH] disconnect as soon as we have no response to appstart --- src/meshcore/meshcore.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/meshcore/meshcore.py b/src/meshcore/meshcore.py index 1c5a373..e3f24a6 100644 --- a/src/meshcore/meshcore.py +++ b/src/meshcore/meshcore.py @@ -93,7 +93,11 @@ class MeshCore: auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts, ) - await mc.connect() + res = await mc.connect() + if res is None: + logger.error("No response from meshcore node, disconnecting") + await mc.disconnect() + return None return mc @classmethod @@ -119,7 +123,12 @@ class MeshCore: auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts, ) - await mc.connect() + res = await mc.connect() + if res is None: + logger.error("No response from meshcore node, disconnecting") + logger.error("Are you sure your node is a serial companion ?") + await mc.disconnect() + return None return mc @classmethod @@ -158,7 +167,11 @@ class MeshCore: max_reconnect_attempts=max_reconnect_attempts, ) - await mc.connect() + res = await mc.connect() + if res is None: + logger.error("No response from meshcore node, disconnecting") + await mc.disconnect() + return None return mc async def connect(self): @@ -167,7 +180,10 @@ class MeshCore: if result is None: await self.dispatcher.stop() raise ConnectionError("Failed to connect to device") - return await self.commands.send_appstart() + res = await self.commands.send_appstart() + if res is None or res.type == EventType.ERROR: + return None + return res async def disconnect(self): """Disconnect from the device and clean up resources."""