Created
October 21, 2019 10:12
-
-
Save geneotech/3632752c49f96c8414bed4976049fd6e to your computer and use it in GitHub Desktop.
test_mqtt.py
This file contains 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 | |
import threading | |
ADDR="test.mosquitto.org" | |
TOPIC_NAME="flow_temp_pres" | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code "+str(rc)) | |
print(client.subscribe(TOPIC_NAME)) | |
def on_message(client, userdata, msg): | |
print("MESSAGE!", msg.topic+" "+ str(msg.payload.decode("utf-8"))) | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.reconnect_delay_set(1, 1) | |
client.connect(ADDR, 1883, 3) | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment