Skip to content

Instantly share code, notes, and snippets.

@chepecarlos
Last active March 12, 2021 03:14
Show Gist options
  • Save chepecarlos/6a8132096bc1b409090e946c9119784a to your computer and use it in GitHub Desktop.
Save chepecarlos/6a8132096bc1b409090e946c9119784a to your computer and use it in GitHub Desktop.
Git de prueba de python con mqtt
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