Skip to content

Commit c9bdaad

Browse files
authored
Merge pull request #3 from makermelissa/main
Place the MQTT Loop in a try/except block
2 parents 06347fc + c609f4c commit c9bdaad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_funhouse/network.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __init__(
6565
)
6666
self._mqtt_client = None
6767
self.mqtt_connect = None
68-
self.mqtt_loop = None
6968
self.mqtt_publish = None
7069

7170
def init_io_mqtt(self):
@@ -95,7 +94,6 @@ def init_mqtt(self, broker, port=1883, username=None, password=None, use_io=Fals
9594
if use_io:
9695
self._mqtt_client = IO_MQTT(self._mqtt_client)
9796
self.mqtt_connect = self._mqtt_client.connect
98-
self.mqtt_loop = self._mqtt_client.loop
9997
self.mqtt_publish = self._mqtt_client.publish
10098

10199
return self._mqtt_client
@@ -107,6 +105,14 @@ def _get_mqtt_client(self):
107105
return self._mqtt_client
108106
raise RuntimeError("Please initialize MQTT before using")
109107

108+
def mqtt_loop(self):
109+
"""Run the MQTT Loop"""
110+
try:
111+
if self._mqtt_client is not None:
112+
self._mqtt_client.loop()
113+
except MQTT.MMQTTException as err:
114+
print("MMQTTException: {0}".format(err))
115+
110116
@property
111117
def on_mqtt_connect(self):
112118
"""

0 commit comments

Comments
 (0)