Created
September 10, 2017 11:50
-
-
Save anonymous/fd03230d2b7566bee901413b7e9fde5a to your computer and use it in GitHub Desktop.
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
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