From 50ea321f66aa0a2486ee3a48f61c1810420ae8f0 Mon Sep 17 00:00:00 2001 From: "DSTO\\pivatom" Date: Tue, 18 Dec 2018 10:15:04 +1030 Subject: [PATCH] Add some comments --- Messaging/mqttsession.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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