Advertisement
Skillkiller

Thinkspeak DTH 22

Jul 2nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #!/usr/bin/python
  2. import thingspeak
  3. import time
  4. import Adafruit_DHT
  5.  
  6. channel_id = 0000 # PUT CHANNEL ID HERE
  7. write_key  = 'ABC' # PUT YOUR WRITE KEY HERE
  8. pin = 4
  9. sensor = Adafruit_DHT.DHT22
  10.  
  11. def measure(channel):
  12.     try:
  13.         humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
  14.         # write
  15.         response = channel.update({'field1': temperature, 'field2': humidity})
  16.        
  17.     except:
  18.         print("connection failed")
  19.  
  20.  
  21. if __name__ == "__main__":
  22.     channel = thingspeak.Channel(id=channel_id, write_key=write_key)
  23.     while True:
  24.         measure(channel)
  25.         # free account has an api limit of 15sec
  26.         time.sleep(15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement