Last active
January 1, 2019 22:26
-
-
Save ReneHollander/3b9986e0dc2136bc07d8a917a14277f9 to your computer and use it in GitHub Desktop.
RaspberryPi read DHT22 with Adafruit_Python_DHT
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
#!/usr/bin/python3 | |
import sys | |
import Adafruit_DHT | |
sensor = Adafruit_DHT.DHT22 | |
sensor_name = sys.argv[1] | |
pin = sys.argv[2] | |
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin, delay_seconds=3) | |
if humidity is not None and temperature is not None: | |
print('ambient,sensor_name={} temperature={:0.1f},humidity={:0.1f}'.format(sensor_name, temperature, humidity)) | |
sys.exit(0) | |
else: | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment