Skip to content

Commit 99504a8

Browse files
committed
fix client not reconnecting
1 parent 5db90ab commit 99504a8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/publisher/mqtt_publisher.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ async def __run_loop(self) -> None:
7777
reconnect_interval = 5
7878
while True:
7979
try:
80+
LOG.debug(
81+
"Connecting to %s:%s as %s",
82+
self.host,
83+
self.port,
84+
self.publisher_id,
85+
)
8086
async with client:
8187
self.__connected.set()
8288
await self.__on_connect()
@@ -88,17 +94,19 @@ async def __run_loop(self) -> None:
8894
message.qos,
8995
message.properties,
9096
)
91-
except aiomqtt.MqttError as e:
97+
except aiomqtt.MqttError:
9298
LOG.error(
93-
f"Connection to MQTT broker lost; Reconnecting in {reconnect_interval} seconds ...: {e}"
99+
"Connection to %s:%s lost; Reconnecting in %d seconds ...",
100+
self.host,
101+
self.port,
102+
reconnect_interval,
94103
)
95104
await asyncio.sleep(reconnect_interval)
96105
except asyncio.exceptions.CancelledError:
97106
LOG.debug("MQTT publisher loop cancelled")
98107
raise
99108
finally:
100109
self.__connected.clear()
101-
self.client = None
102110
LOG.info("MQTT client disconnected")
103111

104112
@override

0 commit comments

Comments
 (0)