Skip to content

Commit 1f3d37b

Browse files
author
Jim Bennett
committed
Fixing reconnect logic after bug fixes in mini MQTT
1 parent dbc03d6 commit 1f3d37b

File tree

1 file changed

+1
-32
lines changed

1 file changed

+1
-32
lines changed

adafruit_azureiot/iot_mqtt.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -426,43 +426,12 @@ def disconnect(self) -> None:
426426
self._mqtt_connected = False
427427
self._mqtts.disconnect()
428428

429-
# Workaround for https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/26
430-
def _fix_broker_name(self, hostname):
431-
try: # set broker IP
432-
self._mqtts.broker = self._iface.unpretty_ip(hostname)
433-
except ValueError: # set broker URL
434-
self._mqtts.broker = hostname
435-
436429
def reconnect(self) -> None:
437430
"""Reconnects to the MQTT broker
438431
"""
439432
self._logger.info("- iot_mqtt :: reconnect :: ")
440433

441-
self._auth_response_received = None
442-
443-
# Workaround for https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/25
444-
# Workaround for https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/26
445-
# Workaround for https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/28
446-
try:
447-
self._fix_broker_name(self._hostname)
448-
self._mqtts.connect()
449-
except ValueError:
450-
self._fix_broker_name("https://" + self._hostname)
451-
self._mqtts.connect()
452-
453-
self._logger.info("- iot_mqtt :: waiting for auth...")
454-
455-
while self._auth_response_received is None:
456-
self.loop()
457-
458-
self._logger.info("- iot_mqtt :: authed, subscribing...")
459-
460-
# Resubscribe
461-
self._subscribe_to_core_topics()
462-
if self._is_subscribed_to_twins:
463-
self._subscribe_to_twin_topics()
464-
465-
self._logger.info("- iot_mqtt :: resubscribed")
434+
self._mqtts.reconnect()
466435

467436
def is_connected(self) -> bool:
468437
"""Gets if there is an open connection to the MQTT broker

0 commit comments

Comments
 (0)