From 8fa2cb83bc687ac639d90835228e713702bc698b Mon Sep 17 00:00:00 2001 From: "DSTO\\pivatom" Date: Wed, 19 Dec 2018 16:31:03 +1030 Subject: [PATCH] Add on disconnect callback to mqtt example --- Messaging/clientEx copy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Messaging/clientEx copy.py b/Messaging/clientEx copy.py index 8b814c9..01d6c3e 100644 --- a/Messaging/clientEx copy.py +++ b/Messaging/clientEx copy.py @@ -18,14 +18,19 @@ def on_message(client, userdata, message): print("Received message '" + p + "' on topic '" + message.topic + "' with QoS " + str(message.qos)) -mqttc = mqtt.Client() +def on_disconnect(client, userdata, rc): + if rc != 0: + print("Unexpected disconnection.") + +mqttc = mqtt.Client(transport="websockets") # mqttc.tls_set_context(context = ssl.create_default_context()) mqttc.on_connect = on_connect +mqttc.on_disconnect = on_disconnect mqttc.on_message = on_message -mqttc.connect('10.1.3.123', 1883, 60) +mqttc.connect('iot.eclipse.org', 1883, 60) mqttc.loop_start()