Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. cientid='d:xlv9uq:Raspberry-Pi3:RaspberryPiDevice1'
  2. username='use-token-auth'
  3. password='thisisatokenforthecreateddevice'
  4. topic='iot-2/evt/temperature/fmt/json'
  5.  
  6. # Sensor parameters
  7. dht_sensor_port = 7
  8.  
  9. client = mqtt.Client(clientid)
  10. client.username_pw_set(username, password)
  11. client.connect(host, 1883, 60)
  12.  
  13. while True:
  14. try:
  15. [ t,h ]=grovepi.dht(dht_sensor_port,0)
  16. client.publish(topic, json.dumps({'t':t, 'h':h}))
  17. print "Message published"
  18. print(str(t) + "\t" + str(h));
  19. time.sleep(.5)
  20. except IOError:
  21. print ("Error")
  22.  
  23. client.loop()
  24. client.disconnect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement