Created
June 14, 2021 10:03
-
-
Save yostane/7dc50f306c58c0a2bc55d079e6186cc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import paho.mqtt.client as mqtt | |
| def on_connect_mqtt(client, userdata, flags, rc): | |
| print(f"rc : {rc}, {userdata}") | |
| client.publish("chambre1/ordi", "Ah !") | |
| res = client.subscribe("chambre1/tv") | |
| print(f"subscribe res : {res}") | |
| res = client.subscribe("chambre1/tv2") | |
| print(f"subscribe res : {res}") | |
| def on_subscribe_mqtt(client, obj, mid, granted_qos): | |
| print(f"Subscribed: {mid} - qos {granted_qos}") | |
| def on_message_mqtt(client, obj, msg): | |
| print(f"{msg.topic} - {msg.qos} - payload {msg.payload}") | |
| def on_publish_mqtt(client, obj, mid): | |
| print(f"client: {client} - obj: {obj} - mid: {mid}") | |
| mqttClient = mqtt.Client() | |
| mqttClient.on_connect = on_connect_mqtt | |
| mqttClient.on_publish = on_publish_mqtt | |
| mqttClient.on_subscribe = on_subscribe_mqtt | |
| mqttClient.on_message = on_message_mqtt | |
| # mqttClient.username_pw_set(login, mot de passe) | |
| mqttClient.username_pw_set("", "") | |
| mqttClient.connect("xxxxx.cloud.shiftr.io", 1883) | |
| # mqttClient.loop_forever() | |
| rc = mqtt.MQTT_ERR_SUCCESS | |
| while rc == mqtt.MQTT_ERR_SUCCESS: | |
| rc = mqttClient.loop() | |
| mqttClient.disconnect() | |
| print("finished") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment