Skip to content

Read DS18B20 temperatures without blocking loop() - #1265

Merged
gskjold merged 1 commit into
UtilitechAS:mainfrom
Allram:pr/temp-nonblocking
Oct 15, 2026
Merged

gskjold merged 1 commit into
UtilitechAS:mainfrom
Allram:pr/temp-nonblocking

Conversation

@Allram

@Allram Allram commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Problem

updateTemperatures() called requestTemperatures() with the library default wait-for-conversion, which blocks for the full conversion time (up to 750 ms at 12 bit). The main loop logs this as Used 1323ms to update temperature every 15 s. On ESP8266 with a software serial HAN port that pause is long enough to overflow the receive buffer.

Fix

Start the conversion asynchronously (setWaitForConversion(false)), return false until 800 ms have passed, then read the values. handleTemperature() already retries on false, so the publish cadence is unchanged; the wait just happens in the background. The first-time init path is left as is.

Tested

ESP8266 with one DS18B20. The 1.3 s warning is gone from the debug log and the reported temperature is unchanged.

updateTemperatures() called requestTemperatures() with the library's
default wait-for-conversion, which blocks for the full conversion time
(up to 750 ms at 12 bit). The main loop logged this as
"Used 1323ms to update temperature" every 15 s. On ESP8266 with a
software serial HAN port that pause is long enough to overflow the
receive buffer.

Start the conversion asynchronously and return false until 800 ms have
passed, then read the values. handleTemperature() already retries on
false, so the publish cadence is unchanged; the only difference is that
the wait happens in the background.
@gskjold
gskjold merged commit 99dbcb6 into UtilitechAS:main Oct 15, 2026
7 of 8 checks passed
@gskjold

gskjold commented Oct 15, 2026

Copy link
Copy Markdown
Member

@Allram Thank you for your contributions, sorry it took me a while to get these tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants