Skip to content

Commit 5493703

Browse files
authored
Merge pull request #17 from jerryneedell/jerryn_None
Fix potential first read issue
2 parents 23254ca + 125890e commit 5493703

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

adafruit_dht.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ def measure(self):
138138
delay_between_readings = 0.5
139139
if self._dht11:
140140
delay_between_readings = 1.0
141-
if time.monotonic()-self._last_called > delay_between_readings:
141+
# Initiate new reading if this is the first call or if sufficient delay
142+
# If delay not sufficient - return previous reading.
143+
# This allows back to back access for temperature and humidity for same reading
144+
if (self._last_called == 0 or
145+
(time.monotonic()-self._last_called) > delay_between_readings):
142146
self._last_called = time.monotonic()
143147

144148
pulses = self._get_pulses()

0 commit comments

Comments
 (0)