-
Notifications
You must be signed in to change notification settings - Fork 124
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
base: master
Are you sure you want to change the base?
Conversation
Added some code to catch 1) the erroneous 0°C temperature reading, 2) the 85°C error reading and 3) the 127.9375°C error reading before they end up in the database. This is based upon work from Chris Petrich: https://github.com/cpetrich/counterfeit_DS18B20 A similar check for conversion success was added to w1_therm kernel module in 2020: https://github.com/torvalds/linux/blame/305230142ae0637213bf6e04f6d9f10bbcb74af8/drivers/w1/slaves/w1_therm.c#L1186-L1197 I did not test this code on a RasPi yet.
src/protocols/MeterW1therm.cpp
Outdated
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 comment
The 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?
private check_quirks(device,buffer){...
if (!check_quirks(device,buffer)) return false;
src/protocols/MeterW1therm.cpp
Outdated
@@ -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: |
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.
thanks for your contribution, good stuff! |
@h-eff: |
i suggest we merge this, even with @h-eff not responding anymore, as it's really useful. can anybody else provide some review? will try to test also, but it's not possible to test those corner-cases in hardware. (we probably should have automated tests for this.) |
As announced here: https://www.photovoltaikforum.com/thread/199267-blitzeinschlag-in-der-nachbarschaft-hat-mir-den-vz-lahmgelegt/?postID=3459011#post3459011 , I've written some code to catch
before they end up in the database. This is based upon work from Chris Petrich: https://github.com/cpetrich/counterfeit_DS18B20
A similar check for conversion success was added to w1_therm kernel module in 2020: https://github.com/torvalds/linux/blame/305230142ae0637213bf6e04f6d9f10bbcb74af8/drivers/w1/slaves/w1_therm.c#L1186-L1197
So when do these readings occur?
This discrimination will work until the serial numbers of genuine DS18B20 reach 0x0001xxxxxxxx. Currently, we are at 0x00000fxxxxxx. I estimate this won't be a problem before 2050.
In my opinion, all of these readings should not end up as spikes in the temperature database, but preferable as debug error in the vzlogger logfile.
As of yet, I still have little experience writing C++, so probably I did not write the best possible code. Please comment on what could be better.
I did not yet test this code on a RasPi. I plan to set up a test system in the next two weeks.