Repository navigation
Read DS18B20 temperatures without blocking loop() - #1265
Merged
Merged
Conversation
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.
Member
|
@Allram Thank you for your contributions, sorry it took me a while to get these tested |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
updateTemperatures()calledrequestTemperatures()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 asUsed 1323ms to update temperatureevery 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)), returnfalseuntil 800 ms have passed, then read the values.handleTemperature()already retries onfalse, 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.