Skip to content

Instantly share code, notes, and snippets.

@icalik
Created July 27, 2017 20:55
Show Gist options
  • Save icalik/b3e50e099113e7d8e85df5860fae0c4f to your computer and use it in GitHub Desktop.
Save icalik/b3e50e099113e7d8e85df5860fae0c4f to your computer and use it in GitHub Desktop.
mqtt_read
#!/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