Skip to content

Instantly share code, notes, and snippets.

@geneotech
Created October 21, 2019 10:12
Show Gist options
  • Save geneotech/3632752c49f96c8414bed4976049fd6e to your computer and use it in GitHub Desktop.
Save geneotech/3632752c49f96c8414bed4976049fd6e to your computer and use it in GitHub Desktop.
test_mqtt.py
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