I'm setting up an automated garden but I'm wondering whether this is the best approach to get readings from a DHT11 temperature sensor and check its content. Since the DHT-Adafruit library won't raise an error if it can't connect with the sensor I ought to check whether the reading is null or not. Here is what I thought about, is there room for improvement/more reliable method?
Thanks in advance,
Code: Select all
def temp_humidity_read(): humidity, temperature = Adafruit_DHT.read_retry(11, 4) if (temperature and humidity) is not None: sensor_reading_write('temperature', temperature) sensor_reading_write('humidity', humidity) else: logging.error('Could not read properly the temperature and' 'humidity sensor')