Created
March 27, 2020 22:58
-
-
Save yazdipour/a5706e8bf904435a80d558e053fb79d1 to your computer and use it in GitHub Desktop.
Python MQTT Pub/Sub
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 #pip install paho.mqtt | |
client = mqtt.Client() | |
client.username_pw_set(username="testuser",password="testpass") | |
client.connect("192.168.0.101", 1883) | |
# PUBLISH | |
client.publish("Topic", "hello server") | |
# SUBSCRIBE | |
def on_message(client, userdata, message): | |
print("Message Recieved: " + message.payload.decode()) | |
client.on_message = on_message | |
client.subscribe("test1", qos=1) | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment