From f464f929fa2b5c2c13ee949da940ab85ea34ae3e Mon Sep 17 00:00:00 2001 From: Pierre Grasswill Date: Tue, 19 May 2026 18:11:44 +0200 Subject: [PATCH] Fix MQTT reconnection in SatelliteController after broker disconnect The listen() loop had two bugs preventing reconnection: 1. except Exception was placed before except aiomqtt.MqttError, making the MqttError handler dead code (Exception catches all) 2. Both except blocks had 'break', exiting the while True loop on first disconnect, so the client never reconnected Fix: swap except order (MqttError before Exception), remove the breaks on connection errors. The existing asyncio.sleep(5) handles backoff. --- cbpi/controller/satellite_controller.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cbpi/controller/satellite_controller.py b/cbpi/controller/satellite_controller.py index 66366133..a82e8c9e 100644 --- a/cbpi/controller/satellite_controller.py +++ b/cbpi/controller/satellite_controller.py @@ -77,11 +77,10 @@ async def listen(self): # Cancel self.logger.warning("MQTT Listening Cancelled") break - except Exception as e: - self.logger.error("MQTT General Exception: {}".format(e)) - break except aiomqtt.MqttError as e: - self.logger.error("MQTT Exception: {}".format(e)) + self.logger.warning("MQTT disconnected: {}. Reconnecting in 5s".format(e)) + except Exception as e: + self.logger.error("MQTT General Exception: {}. Reconnecting in 5s".format(e)) await asyncio.sleep(5)