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:
9:0e103c2f869a
Parent:
8:5980547ae71c
Child:
10:72eb217def1f
--- a/RdDS18B20.cpp	Sat Feb 21 19:00:08 2015 +0000
+++ b/RdDS18B20.cpp	Sun Feb 22 11:57:12 2015 +0000
@@ -10,6 +10,11 @@
 DS18B20::DS18B20(PinName mbedPin) : _oneWire(mbedPin)
 {
     _numValidAddresses = 0;
+    for (int i = 0; i < MAX_BUS_DEVICES; i++)
+    {
+        _temperatureTable[i] = INVALID_TEMPERATURE;
+        _timeOfReadingTable[i] = 0;    
+    }
 }
 
 // Request conversion
@@ -22,11 +27,11 @@
 }
 
 // Get temperature
-double DS18B20::GetTemperature(int addrIdx)
+double DS18B20::ReadTemperature(int addrIdx)
 {
     // Check valid address
     if ((addrIdx >= _numValidAddresses) || (addrIdx < 0))
-        return -1000.0;
+        return INVALID_TEMPERATURE;
     
     // Init the bus and req reading
     _oneWire.init();
@@ -49,14 +54,22 @@
     
     // Convert temperature
     double temperature = ((temperatureVals[1] * 256) + temperatureVals[0])*0.0625;
+    _temperatureTable[addrIdx] = temperature;
+    _timeOfReadingTable[addrIdx] = time(NULL);
     return temperature; 
 }
 
 // Get address for a device
-uint8_t* DS18B20::GetAddress(int addrIdx)
+uint8_t* DS18B20::GetAddress(int addrIdx, uint8_t* addrBufPtr)
 {
     if ((addrIdx >= _numValidAddresses) || (addrIdx < 0))
         return _addrTable[0];
+    // Make a copy if non-null pointer passed in
+    if (addrBufPtr != NULL)
+    {
+        for( int i = 0; i < ONEWIRE_ADDR_BYTES; i++) 
+            addrBufPtr[i] = _addrTable[addrIdx][i];
+    }
     return _addrTable[addrIdx];
 }
 
@@ -85,6 +98,14 @@
     printf(GetAddressStr(addrIdx));
 }
 
+double DS18B20::GetLatestTemperature(int addrIdx, time_t& timeOfReading)
+{
+    if ((addrIdx >= _numValidAddresses) || (addrIdx < 0))
+        return INVALID_TEMPERATURE;
+    timeOfReading = _timeOfReadingTable[addrIdx];
+    return _temperatureTable[addrIdx];
+}
+
 void DS18B20::SearchToGetAddresses()
 {
     _numValidAddresses = 0;
@@ -104,7 +125,7 @@
 #ifdef SHOW_18B20_DEBUGGING
         printf("Found device addr (ROM) =");
 #endif
-        for( int i = 0; i < 8; i++) 
+        for( int i = 0; i < ONEWIRE_ADDR_BYTES; i++) 
         {
             // Copy to table
             _addrTable[_numValidAddresses][i] = addr[i];