13 lines
401 B
Python
13 lines
401 B
Python
|
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
|