Last active
October 21, 2019 10:31
-
-
Save geneotech/b592ce147c61f6beafd9f9f85b74dc0c to your computer and use it in GitHub Desktop.
test_mqtt2.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="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