From 66bdd91132437c4ce1c1152b03dd529f846baaec Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Apr 2021 08:32:07 -0700 Subject: [PATCH 1/3] Place the MQTT Loop in a try/except block --- adafruit_funhouse/network.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index 10f17c4..e3d4037 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -65,7 +65,6 @@ def __init__( ) self._mqtt_client = None self.mqtt_connect = None - self.mqtt_loop = None self.mqtt_publish = None def init_io_mqtt(self): @@ -95,7 +94,6 @@ def init_mqtt(self, broker, port=1883, username=None, password=None, use_io=Fals if use_io: self._mqtt_client = IO_MQTT(self._mqtt_client) self.mqtt_connect = self._mqtt_client.connect - self.mqtt_loop = self._mqtt_client.loop self.mqtt_publish = self._mqtt_client.publish return self._mqtt_client @@ -107,6 +105,13 @@ def _get_mqtt_client(self): return self._mqtt_client raise RuntimeError("Please initialize MQTT before using") + def mqtt_loop(self): + """Run the MQTT Loop""" + try: + self._mqtt_client.loop + except MQTT.MMQTTException: + pass + @property def on_mqtt_connect(self): """ From fff777954fdb7793ed16b27dbfe1deed4bc7af87 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Apr 2021 08:33:49 -0700 Subject: [PATCH 2/3] Make sure mqtt is set up first --- adafruit_funhouse/network.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index e3d4037..676efc2 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -108,7 +108,8 @@ def _get_mqtt_client(self): def mqtt_loop(self): """Run the MQTT Loop""" try: - self._mqtt_client.loop + if self._mqtt_client is not None: + self._mqtt_client.loop() except MQTT.MMQTTException: pass From c609f4c5d2b4b42ff159c6b7a1781ecf43edf7aa Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 7 Apr 2021 09:07:31 -0700 Subject: [PATCH 3/3] Print the error, but continue anyways --- adafruit_funhouse/network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index 676efc2..17d9885 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -110,8 +110,8 @@ def mqtt_loop(self): try: if self._mqtt_client is not None: self._mqtt_client.loop() - except MQTT.MMQTTException: - pass + except MQTT.MMQTTException as err: + print("MMQTTException: {0}".format(err)) @property def on_mqtt_connect(self):