Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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