Add some comments

This commit is contained in:
DSTO\pivatom
2018-12-18 10:15:04 +10:30
parent 663f6a8c49
commit 50ea321f66

View File

@@ -3,8 +3,13 @@ import paho.mqtt.client as mqtt
client = None client = None
host = 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. # Arguably not needed, just want to make the client static, but here anyway.
def connect(): def connect():
global client
if client is None or host is None: if client is None or host is None:
print("Error: Client and/or host are not initialised.") print("Error: Client and/or host are not initialised.")
else: else:
@@ -12,6 +17,7 @@ def connect():
client.loop_start() client.loop_start()
def disconnect(): def disconnect():
global client
if client is not None: if client is not None:
client.loop_stop() client.loop_stop()
client.disconnect() client.disconnect()
@@ -19,7 +25,8 @@ def disconnect():
print("Error: Client is not initialised.") print("Error: Client is not initialised.")
def Client(): def Client():
if client is not None: global client
return mqtt.Client() if client is None:
else: client = mqtt.Client()
return client
return client