Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cientid='d:xlv9uq:Raspberry-Pi3:RaspberryPiDevice1'
- username='use-token-auth'
- password='thisisatokenforthecreateddevice'
- topic='iot-2/evt/temperature/fmt/json'
- # Sensor parameters
- dht_sensor_port = 7
- client = mqtt.Client(clientid)
- client.username_pw_set(username, password)
- client.connect(host, 1883, 60)
- while True:
- try:
- [ t,h ]=grovepi.dht(dht_sensor_port,0)
- client.publish(topic, json.dumps({'t':t, 'h':h}))
- print "Message published"
- print(str(t) + "\t" + str(h));
- time.sleep(.5)
- except IOError:
- print ("Error")
- client.loop()
- client.disconnect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement