diff --git a/requirements.txt b/requirements.txt index c8cbd80..6b5ceca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ gpiozero luma.led_matrix fastapi uvicorn -fastapi-cors \ No newline at end of file +fastapi-cors +Adafruit_DHT \ No newline at end of file diff --git a/src/climate.py b/src/climate.py new file mode 100644 index 0000000..e950eec --- /dev/null +++ b/src/climate.py @@ -0,0 +1,13 @@ +import Adafruit_DHT + +class Dht22Sensor: + def __init__(self, pin): + self.sensor = Adafruit_DHT.DHT22 + self.pin = pin + + def read(self): + humidity, temperature = Adafruit_DHT.read_retry(self.sensor, self.pin) + if humidity is not None and temperature is not None: + return {'temperature': temperature, 'humidity': humidity} + else: + return None \ No newline at end of file diff --git a/src/index.html b/src/index.html index 2885f91..6505814 100644 --- a/src/index.html +++ b/src/index.html @@ -20,7 +20,9 @@ - + + +