Skip to content

Place the MQTT Loop in a try/except block #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions adafruit_funhouse/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -107,6 +105,14 @@ 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:
if self._mqtt_client is not None:
self._mqtt_client.loop()
except MQTT.MMQTTException as err:
print("MMQTTException: {0}".format(err))

@property
def on_mqtt_connect(self):
"""
Expand Down