diff --git a/Messaging/mqttsession.py b/Messaging/mqttsession.py index f791b64..bbad0b7 100644 --- a/Messaging/mqttsession.py +++ b/Messaging/mqttsession.py @@ -3,8 +3,13 @@ import paho.mqtt.client as mqtt client = None host = None +""" +Wrapper module for paho mqtt library, providing a singleton instance of the client to be used. +""" + # Arguably not needed, just want to make the client static, but here anyway. def connect(): + global client if client is None or host is None: print("Error: Client and/or host are not initialised.") else: @@ -12,6 +17,7 @@ def connect(): client.loop_start() def disconnect(): + global client if client is not None: client.loop_stop() client.disconnect() @@ -19,7 +25,8 @@ def disconnect(): print("Error: Client is not initialised.") def Client(): - if client is not None: - return mqtt.Client() - else: - return client + global client + if client is None: + client = mqtt.Client() + + return client