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:
2026-08-17 22:58:30 +08:00
co-authored by Cursor
parent f061673880
commit 7da6ced1c4
5 changed files with 313 additions and 38 deletions
+4 -4
View File
@@ -34,11 +34,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:
@@ -48,7 +48,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'])