Read the DHT sensor with lgpio instead of Adafruit bitbang.
Userspace pulse timing misses DHT22 edges on Raspberry Pi OS, which produced empty readings. Log the real failure reason and clarify that PIN is BCM GPIO numbering. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -29,11 +29,11 @@ def sensor_read(cfg, dev_type, dhtpin):
|
||||
for num in range(cfg['retries']):
|
||||
try:
|
||||
t, h = dhtreader.read(dev_type, dhtpin)
|
||||
except Exception:
|
||||
except Exception as err:
|
||||
if num + 1 < cfg['retries']:
|
||||
logging.warning(
|
||||
'Exception during sensor read; retry %d/%d',
|
||||
num + 1, cfg['retries'],
|
||||
'Exception during sensor read; retry %d/%d: %s',
|
||||
num + 1, cfg['retries'], err,
|
||||
)
|
||||
time.sleep(cfg['timeout'])
|
||||
else:
|
||||
@@ -43,7 +43,7 @@ def sensor_read(cfg, dev_type, dhtpin):
|
||||
)
|
||||
continue
|
||||
|
||||
if not t or not h:
|
||||
if t is None or h is None:
|
||||
logging.warning('Sensor returned empty reading; retrying.')
|
||||
if num + 1 < cfg['retries']:
|
||||
time.sleep(cfg['timeout'])
|
||||
|
||||
Reference in New Issue
Block a user