Fixed temphum sensor
Build, push image, and notify Watchtower / build-image (push) Successful in 43s
Build, push image, and notify Watchtower / notify (push) Successful in 17s

This commit is contained in:
2026-08-16 14:23:28 +02:00
parent fd00c9a89d
commit 0469b3d406
+17 -6
View File
@@ -15,17 +15,28 @@ white = 1 # The White colored sensor.
def get_temperature_and_humidity():
with grove_lock:
try:
[temp, humidity] = grovepi.dht(sensor, blue)
if math.isnan(temp) == False and math.isnan(humidity) == False:
if not math.isnan(temp) and not math.isnan(humidity) and temp > -40 and humidity >= 0:
return temp, humidity
else:
print("Error reading from DHT sensor")
except Exception:
pass
return None, None
def get_temperature_and_humidity_with_retry(max_retries=3):
for _ in range(max_retries): # Try up to max_retries times
def get_temperature_and_humidity_with_retry(max_retries=4, retry_delay=1.5):
"""
Reads temperature and humidity with retries.
Uses a 1.5s delay between attempts to respect DHT sampling limits.
"""
for attempt in range(max_retries):
temp, humidity = get_temperature_and_humidity()
if temp is not None and humidity is not None:
return temp, humidity
time.sleep(1) # Wait a bit before retrying
# Wait before retrying (DHT sensors require >= 1s between reads)
if attempt < max_retries - 1:
time.sleep(retry_delay)
print("Warning: All DHT sensor read attempts failed.")
return None, None