Skip to content

Instantly share code, notes, and snippets.

@tolgahancepel
Created May 13, 2022 18:04
Show Gist options
  • Save tolgahancepel/059575bea3c947b94d882913b9b32103 to your computer and use it in GitHub Desktop.
Save tolgahancepel/059575bea3c947b94d882913b9b32103 to your computer and use it in GitHub Desktop.
# -----------------------------------------------------------------------------
# MQTT Subscribe
# -----------------------------------------------------------------------------
mqttc = mqtt.Client()
mqttc.connect("mqtt.eclipseprojects.io", 1883, 60)
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
mqttc.subscribe("myroom/temperature")
def on_message(client, userdata, msg):
global current_temperature
current_temperature = msg.payload.decode()
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.loop_start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment