-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update MeterW1therm.cpp to catch erroneous temperature values #610
Open
h-eff
wants to merge
2
commits into
volkszaehler:master
Choose a base branch
from
h-eff:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,8 +83,50 @@ bool MeterW1therm::W1sysHWif::readTemp(const std::string &device, double &value) | |
print(log_debug, "CRC not ok from %s (%s)", "w1t", dev.c_str(), buffer); | ||
} else { | ||
// crc ok | ||
// now parse t=<value> | ||
// now check for other errors: | ||
if (fgets(buffer, 100, fp)) { // e.g. 07 01 55 00 7f ff 0c 10 18 t=16437 | ||
|
||
///// Start of new code: Catch DS18B20-specific errors. ///// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe put this into a function to isolate it, instead of surrounding with comments? |
||
/// For reference: https://github.com/cpetrich/counterfeit_DS18B20 | ||
/// Check byte 6 of scratchpad to recognize error readings. | ||
/// Genuine DS18B20 compute byte 6 as the difference from | ||
/// 00001111 & <byte 0> to 00010000; most clones always use 0x0c. | ||
/// Genuine DS18B20 are still in the 00000xxxxxxx address range | ||
/// as of 2023; clones are not. | ||
|
||
// Check for sensor family DS18B20 via device == "28*": | ||
if (device[0]=='2' && device[1]=='8') { | ||
if (!strncmp(buffer,"00 00 00 00 00 00 00 00 00",26)) { | ||
// According to DS18B20 datasheet, this scratchpad-reading MUST be wrong. | ||
print(log_debug, "only zeroes from %s (%s), " | ||
"the 1wire-bus is probably unstable", "w1t", dev.c_str(), buffer); | ||
return false; | ||
} | ||
// if (buffer == "?? ?? ?? ?? ?? ?? 0c*"), maybe an error has happened: | ||
if (buffer[18]=='0' && buffer[19]=='c') { | ||
// only do this handling for genuine DS18B20, e.g. device="28-0000*": | ||
if (device[3]=='0' && buffer[4]=='0' && buffer[5]=='0' && buffer[6]=='0') { | ||
// if (buffer == "50 05*"), 0x0550/16 = 85 degrees Celsius | ||
if (!strncmp(buffer,"50 05",5)) { | ||
// Sensor returned default boot-up value; did not complete temperature conversion. | ||
print(log_debug, "85 degree error from %s (%s), " | ||
"the 1wire-bus is probably unstable", "w1t", dev.c_str(), buffer); | ||
return false; | ||
} | ||
// (if buffer == "ff 07*"), 0x07ff/16 = 127.9375 degrees Celsius | ||
if (!strncmp(buffer,"ff 07",5)) { | ||
// Sensor returned code for insufficient power during temperature conversion. | ||
// This can happen in parasitic 2-wire circuits with floating Vcc pins. | ||
print(log_debug, "insufficient power error from %s (%s), " | ||
"maybe Vcc was left floating", "w1t", dev.c_str(), buffer); | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
///// End of new code. ///// | ||
|
||
// now parse t=<value> | ||
char *pos = strstr(buffer, "t="); | ||
if (pos) { | ||
pos += 2; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is misplaced...
the result of
fgets()
is not only for error-checking, it's also what the reading is parsed from.