Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2017 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fd03230d2b7566bee901413b7e9fde5a to your computer and use it in GitHub Desktop.
Save anonymous/fd03230d2b7566bee901413b7e9fde5a 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 {0}'.format(rc))
client.subscribe('temp_humidity')
def on_message(client,userdata,msg):
t,h=[float(x) for x in msg.payload.decode("utf-8").split(',')]
print('{0}C {1}%'.format(t,h))
#display_data(t,h)
client=mqtt.Client()
client.username_pw_set('username','password')
client.connect("m11.cloudmqtt.com",port=12637,keepalive=60,bind_address='0.0.0.0')
client.on_connect=on_connect
client.on_message=on_message
#client.subscribe("")
client.loop_start()
input("Press enter to terminate")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment