Skip to content

Instantly share code, notes, and snippets.

@unixweb
Last active May 8, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unixweb/2aa16b137f9be5c42b13d1df8cbeeb40 to your computer and use it in GitHub Desktop.
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
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)
@unixweb
Copy link
Author

unixweb commented May 8, 2018

Result in Grafana
bildschirmfoto 2018-05-08 um 11 13 24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment