Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import thingspeak
- import time
- import Adafruit_DHT
- channel_id = 0000 # PUT CHANNEL ID HERE
- write_key = 'ABC' # PUT YOUR WRITE KEY HERE
- pin = 4
- sensor = Adafruit_DHT.DHT22
- def measure(channel):
- try:
- humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
- # write
- response = channel.update({'field1': temperature, 'field2': humidity})
- except:
- print("connection failed")
- if __name__ == "__main__":
- channel = thingspeak.Channel(id=channel_id, write_key=write_key)
- while True:
- measure(channel)
- # free account has an api limit of 15sec
- time.sleep(15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement