Created
July 27, 2017 20:55
-
-
Save icalik/b3e50e099113e7d8e85df5860fae0c4f to your computer and use it in GitHub Desktop.
mqtt_read
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
#!/usr/bin/env python | |
import paho.mqtt.client as mqtt | |
def on_connect(client, data, flags, rc): | |
#print ("Connected with rc: " + str(rc)) | |
client.subscribe("/test1") | |
def on_message(client, obj, msg): | |
print ("Topic: "+ msg.topic+"\nMessage: "+ str(msg.payload)) | |
if "green" in str(msg.payload): | |
print(" Green on!") | |
else: | |
print(" Green off!") | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.on_message = on_message | |
client.connect("m21.cloudmqtt.com", 14998, 60) | |
client.username_pw_set("zxhrcvda", "8yH1WnYy1fRF") | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment