Skip to content

Instantly share code, notes, and snippets.

@matsubo
Last active June 14, 2020 02:01
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 matsubo/fa979b2284f45b1b14ad42310e954ed3 to your computer and use it in GitHub Desktop.
Save matsubo/fa979b2284f45b1b14ad42310e954ed3 to your computer and use it in GitHub Desktop.
[plugin.metrics.dht11]
command = "sudo -u pi python3 /home/pi/DHT11_Python/mackerel.py"
type = "metric"
import RPi.GPIO as GPIO
import dht11
import time
import datetime
# initialize GPIO
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
try:
instance = dht11.DHT11(pin=4)
result = instance.read()
time = int(time.time())
if result.is_valid():
print("custom.dht11.temp-inside\t%-3.1f\t%d" % (result.temperature, time))
print("custom.dht11.humid-inside\t%-3.1f\t%d" % (result.humidity, time))
print("custom.dht11.di-inside\t%-3.1f\t%d" % ((0.81*(float(result.temperature))+0.01*(float(result.humidity))*(0.99*(float(result.temperature))-14.3)+46.3), time))
except KeyboardInterrupt:
print("Cleanup")
GPIO.cleanup()
try:
instance = dht11.DHT11(pin=14)
result = instance.read()
if result.is_valid():
print("custom.dht11.temp-out\t%-3.1f\t%d" % (result.temperature, time))
print("custom.dht11.humid-out\t%-3.1f\t%d" % (result.humidity, time))
print("custom.dht11.di-out\t%-3.1f\t%d" % ((0.81*(float(result.temperature))+0.01*(float(result.humidity))*(0.99*(float(result.temperature))-14.3)+46.3), time))
except KeyboardInterrupt:
print("Cleanup")
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment