Skip to content

Commit a1c82d4

Browse files
committed
Fix on mqtt disconnect
1 parent c15beab commit a1c82d4

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/isar/services/service_connections/mqtt/mqtt_client.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,22 @@ def run(self) -> None:
106106
)
107107

108108
def on_connect(self, client, userdata, flags, reason_code, properties):
109-
self.logger.info(
110-
"Connection returned result: " + mqtt.connack_string(reason_code)
109+
self.logger.info(f"Connected: {reason_code}")
110+
111+
def on_disconnect(self, client, userdata, *args):
112+
if len(args) == 1:
113+
reason_code = args[0]
114+
elif len(args) == 2:
115+
reason_code, _ = args
116+
elif len(args) == 3:
117+
_, reason_code, _ = args
118+
else:
119+
reason_code = None
120+
121+
self.logger.warning(
122+
f"Unexpected disconnection from MQTT Broker: {reason_code}."
111123
)
112124

113-
def on_disconnect(self, client, userdata, reason_code, properties):
114-
if reason_code != 0:
115-
self.logger.warning(
116-
f"Unexpected disconnection from MQTT Broker, {reason_code}"
117-
)
118-
119125
@backoff.on_exception(
120126
backoff.expo,
121127
ConnectionRefusedError,

0 commit comments

Comments
 (0)