Last active
March 12, 2021 03:14
-
-
Save chepecarlos/6a8132096bc1b409090e946c9119784a to your computer and use it in GitHub Desktop.
Git de prueba de python con mqtt
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 | |
def on_connect(client, userdata, flags, rc): | |
print("Se conecto a con mqtt "+str(rc)) | |
client.subscribe("ALSW/#") | |
def on_message(client, userdata, msg): | |
if msg.topic == "ALSW/temp": | |
print(f"Temperatura es {str(msg.payload)}") | |
print(msg.topic+" "+str(msg.payload)) | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.connect("test.mosquitto.org", 1883, 60) | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment