Skip to content

Instantly share code, notes, and snippets.

@tolgahancepel
Last active May 21, 2022 19:52
Show Gist options
  • Select an option

  • Save tolgahancepel/9e81cf90493994afd6c2114ac7d5a628 to your computer and use it in GitHub Desktop.

Select an option

Save tolgahancepel/9e81cf90493994afd6c2114ac7d5a628 to your computer and use it in GitHub Desktop.
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
mqttc.subscribe("myroom/temperature")
def on_message(client, userdata, msg):
print("Received:", msg.payload.decode())
mqttc = mqtt.Client()
mqttc.connect("mqtt.eclipseprojects.io", 1883, 60)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment