Created
May 13, 2022 18:04
-
-
Save tolgahancepel/059575bea3c947b94d882913b9b32103 to your computer and use it in GitHub Desktop.
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
# ----------------------------------------------------------------------------- | |
# 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