Last active
June 14, 2020 02:01
-
-
Save matsubo/fa979b2284f45b1b14ad42310e954ed3 to your computer and use it in GitHub Desktop.
This file contains 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
[plugin.metrics.dht11] | |
command = "sudo -u pi python3 /home/pi/DHT11_Python/mackerel.py" | |
type = "metric" |
This file contains 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 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