Skip to content

Instantly share code, notes, and snippets.

@geneotech
Last active October 21, 2019 10:31
Show Gist options
  • Save geneotech/b592ce147c61f6beafd9f9f85b74dc0c to your computer and use it in GitHub Desktop.
Save geneotech/b592ce147c61f6beafd9f9f85b74dc0c to your computer and use it in GitHub Desktop.
test_mqtt2.py
import paho.mqtt.client as mqtt
import threading
ADDR="192.168.2.128"
TOPIC_NAME="BMS/P11"
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)
print("Connecting...")
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