Add on disconnect callback to mqtt example

This commit is contained in:
DSTO\pivatom
2018-12-19 16:31:03 +10:30
parent 3387a54133
commit 8fa2cb83bc

View File

@@ -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()