Last active
May 8, 2018 12:15
-
-
Save unixweb/2aa16b137f9be5c42b13d1df8cbeeb40 to your computer and use it in GitHub Desktop.
Read Sensors Data from DHT11 / DHT22 and push the data into a InfluxDB every 5 seconds
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 Adafruit_DHT | |
import requests | |
from time import sleep | |
import time | |
DELAY_INTERVAL = 5 | |
dht_sensor = Adafruit_DHT.DHT22 | |
DHT_PIN = 4 | |
# timestamp = time.time() | |
while True: | |
humidity, temperature = Adafruit_DHT.read_retry(dht_sensor, DHT_PIN) | |
timestamp = time.time() | |
data = 'temp,host=rpi1,location=roaming value=' + str(temperature) | |
print data | |
output = requests.post('http://192.168.1.100:8086/write?db=sensors', data=data) | |
print output | |
data = 'humidity,host=rpi1,location=roaming value=' + str(humidity) | |
print data | |
output = requests.post('http://192.168.1.100:8086/write?db=sensors', data=data) | |
print output | |
print "Humidity: {:0.1f}%, Temperature: {:0.2f}*C".format(humidity, temperature) | |
sleep(DELAY_INTERVAL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result in Grafana
