Last active
May 23, 2018 04:48
-
-
Save jackyyeh5111/eae64a5078816b804ad36c437af957c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sys | |
import Adafruit_DHT | |
import requests | |
import time | |
headers = {'X-AIO-KEY':'b89e5148eebe4f7b9eb366de79deabba'} | |
sensor = Adafruit_DHT.DHT11 | |
pin = 4 # GPIO4 (Raspberry Pi 3 pin 7) | |
while True: | |
# Try to grab a sensor reading. Use the read_retry method which will retry up | |
# to 15 times to get a sensor reading (waiting 2 seconds between each retry). | |
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) | |
if humidity is not None and temperature is not None: | |
print ("Temp=%.1f" % temperature) | |
print ("Humidity=%.1f" % humidity) | |
# use http post to upload sensor value | |
res = requests.post('https://io.adafruit.com/api/v2/Leohom/feeds/sensor/data', {"value":temperature}, headers=headers) | |
print(res.json()) | |
else: | |
print('Failed to get reading. Try again!') | |
sys.exit(1) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment