Monitor for central heating system (e.g. 2zones+hw) Supports up to 15 temp probes (DS18B20/DS18S20) 3 valve monitors Gas pulse meter recording Use stand-alone or with nodeEnergyServer See http://robdobson.com/2015/09/central-heating-monitor
Dependencies: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
Revision 13:9ec0e11cf3c1, committed 2015-02-22
- Comitter:
- Bobty
- Date:
- Sun Feb 22 22:33:25 2015 +0000
- Parent:
- 12:a52996515063
- Child:
- 14:3c3aa4fd7e1a
- Commit message:
- Increased checking on temperature values (bounds and CRC)
Changed in this revision
| RdDS18B20.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/RdDS18B20.cpp Sun Feb 22 22:08:37 2015 +0000
+++ b/RdDS18B20.cpp Sun Feb 22 22:33:25 2015 +0000
@@ -43,7 +43,7 @@
_oneWire.writeByte(0xBE);
// Temperature val
- int temperatureVals[] = {0,0};
+ unsigned char temperatureVals[9];
// Read values back
for (int i = 0; i < sizeof(temperatureVals)/sizeof(int); i++)
@@ -52,8 +52,33 @@
}
_oneWire.init();
+ // Check the CRC
+ if (_oneWire.CRC(temperatureVals, sizeof(temperatureVals)/sizeof(int)-1) == temperatureVals[sizeof(temperatureVals)/sizeof(int)-1])
+ {
+#ifdef SHOW_18B20_DEBUGGING
+ printf("Temp CRC Fail\r\n");
+#endif
+ return INVALID_TEMPERATURE;
+ }
+ else
+ {
+#ifdef SHOW_18B20_DEBUGGING
+ double temperature = ((((int)(temperatureVals[1])) * 256) + temperatureVals[0])*0.0625;
+ printf("Temp = %0.1f", temperature);
+#endif
+ }
+
// Convert temperature
- double temperature = ((temperatureVals[1] * 256) + temperatureVals[0])*0.0625;
+ double temperature = ((((int)(temperatureVals[1])) * 256) + temperatureVals[0])*0.0625;
+
+ // Do a bounds check
+ if ((temperature < -10) || (temperature > 100))
+ {
+#ifdef SHOW_18B20_DEBUGGING
+ printf("Temp out of bounds\r\n");
+#endif
+ return INVALID_TEMPERATURE;
+ }
_temperatureTable[addrIdx] = temperature;
_timeOfReadingTable[addrIdx] = time(NULL);
return temperature;