DS18B20 sensors.requestTemperatures memory for Previous value

HI!

It is possible to call the value of the DS18b20 sensor and in case the value is -127 or 85, prints the previous value, which was for example "20.00C" :o
(somehow remember the previous value.)
In the case if it is also previus value -127 or 85, print "no data"

Now i use "0", And I do not like it

if (temp3 == -127 || temp3 == 85){
          client.print("0");
          client.println("C");
          }
          else{
          client.print(temp3); 
          client.println("C");
           }

If I disconect sensor or no answer, I want to keep the last value

I want to keep the last value

So, do that. What is the problem? Here's a hint. A variable named lastTemp3 looks like a good starting point.

Wauuuu paulS thankyou :smiley:
That was much easier than I expected.
I did not know it was even possible.

At the end of loop i add:

lastvalue1 = value1;
lastvalue2 = value2;
 lastvalue3 = value3;

and IF function for -127

This will solve all my problems with my project with stove and 17 ds18b20 sensors
and monitoring temperature.....

Sometimes it happens that it does not read the value of all sensor (Too long line - disturbance)
This happens only 3-5 times on 4 hours only on random sensor ( reading every 30s ),
but PC Software monitor "0" value,
and then is Sucks graph...

Regards

Pauls,
out of curiosity, there is command for 'before last' or 'before before last' ?

PaulS:
So, do that. What is the problem? Here's a hint. A variable named lastTemp3 looks like a good starting point.

another approach would be to use a local variable for the reading and then assign it to the sensor's kept value if it passes the test... I'd not want to add even more global variables to OP's project.

svedr:
Sometimes it happens that it does not read the value of all sensor (Too long line - disturbance)
This happens only 3-5 times on 4 hours only on random sensor ( reading every 30s ),

So, if you get a bad reading at the regular 30 second interval just read it again (and again) until you get a good reading...

if you have more than one sensor on the bus, you can read them all and create an array with any bad readings and re-read that array until they all go away...

Note: you can also use CRC checks with the DS temperature sensors... you can look at the OneWire::crc8() function

At the end of loop i add:

Why would you set lastTemp3 to temp3, if temp3 is bad?

PaulS:
Why would you set lastTemp3 to temp3, if temp3 is bad?

maybe 'cuz you hinted at him to do so?

:grinning:

for test i try your hint on this code, - expresso - and i see current value and last value…

For me is good :smiley:

or no ??

#include <SPI.h>         
#include <Ethernet.h>
#include <TextFinder.h>

#include <LiquidCrystal_I2C.h>
byte mac[] = { 0x70, 0xD9, 0xE2, 0x38, 0x48, 0x86 }; //mac address of ethernet shield
IPAddress server(192, 168, 5, 91);
IPAddress ip(192, 168, 5, 98); 
IPAddress gateway(192, 168, 5, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetClient client;
TextFinder  finder( client );  
LiquidCrystal_I2C lcd1(0x3B, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

float value1;
float value2; 
float value3; 
float lastvalue1; 
float lastvalue2; 
float lastvalue3; 
int counter = 0; 
void setup()
{
  Serial.begin(115200);
  Ethernet.begin(mac, ip);
  lcd1.begin(20, 4);
  //pinMode(4, OUTPUT);
  //digitalWrite(4, HIGH);
    
  Serial.println("connecting...");
  //delay(10000);
}


void loop(){
    
    {
  if (client.connect(server, 80)) {
    Serial.print("connected... ");
    client.println("GET / HTTP/1.1");
    client.println("Host: 192.168.5.91");
    client.println();
  } else {
    Serial.println("connection failed");
  }
  if (client.connected()) {
    
    
      if(finder.find("Kurnica:")){     
         value1 = finder.getFloat(".");
         Serial.println();
         Serial.println("Kurnica:");      
         Serial.print(value1);
         Serial.print(" C"); 
          lcd1.setCursor(0, 0);
          lcd1.print("Kurnica:");
          lcd1.setCursor(14, 0 );
          lcd1.print(value1,2);//
         }       
         
       if(finder.find("Zunaj:")){     
         value2 = finder.getFloat(".");
         Serial.println();
         Serial.println("Zunaj:");      
         Serial.print(value2);
         Serial.print(" C");
         lcd1.setCursor(0, 1);
         lcd1.print("Zunaj:");
         lcd1.setCursor(14, 1);
         lcd1.print(value2,2);//   
         }    
          
       if(finder.find("Garaza:")){     
         value3 = finder.getFloat(".");
         Serial.println();
         Serial.println("Garaza:");      
         Serial.print(value3);
         Serial.print(" C");  
         lcd1.setCursor(0, 2);
         lcd1.print("Garaza:");
         lcd1.setCursor(14, 2);
         lcd1.print(value3,2);//        
         }
         Serial.println();
    Serial.print("prejšnje vrednosti");
     Serial.println();
    Serial.print(lastvalue1);
    Serial.println();
    Serial.print(lastvalue2);
    Serial.println();
    Serial.print(lastvalue3);
    Serial.println();
    lastvalue1 = value1;
    lastvalue2 = value2;
    lastvalue3 = value3;
    counter = counter + 1;
    Serial.println();
    Serial.println("Counter of readings:");
    Serial.print(counter);
    Serial.println();
    
    }
    
    
    delay(10000); // check again in 10 seconds
   
  }
 
  client.stop();
  
}

PaulS:
Why would you set lastTemp3 to temp3, if temp3 is bad?

Becouse if temp3 is always bad (-127 ), then it must be lasttemp3 always bad (-127 ).
Otherwise I do not know if the sensor is defective.

If temp3 sometimes bad,then lasttemp3 show previus good value ....

Thats good for monitoring, I have no fall to 0 or -127 ( from 80C onin stove ) , its not normal..

svedr:
for test i try your hint on this code, - expresso - and i see current value and last value…

For me is good :smiley:

or no ??

I was thinking more like this:

#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>

#include <LiquidCrystal_I2C.h>
byte mac[] = { 0x70, 0xD9, 0xE2, 0x38, 0x48, 0x86 }; //mac address of ethernet shield
IPAddress server(192, 168, 5, 91);
IPAddress ip(192, 168, 5, 98);
IPAddress gateway(192, 168, 5, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetClient client;
TextFinder  finder( client );
LiquidCrystal_I2C lcd1(0x3B, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

float value1;
float value2;
float value3;
//float lastvalue1;
//float lastvalue2;
//float lastvalue3;
int counter = 0;
void setup()
{
  Serial.begin(115200);
  Ethernet.begin(mac, ip);
  lcd1.begin(20, 4);
  //pinMode(4, OUTPUT);
  //digitalWrite(4, HIGH);

  Serial.println("connecting...");
  //delay(10000);
}


void loop() {

  {
    if (client.connect(server, 80)) {
      Serial.print("connected... ");
      client.println("GET / HTTP/1.1");
      client.println("Host: 192.168.5.91");
      client.println();
    } else {
      Serial.println("connection failed");
    }
    if (client.connected()) {


      if (finder.find("Kurnica:")) {
        float finderValue = finder.getFloat(".");
        if(finderValue != -127 or finderValue != 85)
        {
          value1 = finderValue;
          Serial.println();
          Serial.println("Kurnica:");
          Serial.print(value1);
          Serial.print(" C");
          lcd1.setCursor(0, 0);
          lcd1.print("Kurnica:");
          lcd1.setCursor(14, 0 );
          lcd1.print(value1, 2); //
        }
        else
        {
          Serial.println(F("bad Kurnica value"));
        }
        
      }

      if (finder.find("Zunaj:")) {
        float finderValue = finder.getFloat(".");
        if(finderValue != -127 or finderValue != 85)
        {
          value2 = finderValue;
          Serial.println();
          Serial.println("Zunaj:");
          Serial.print(value2);
          Serial.print(" C");
          lcd1.setCursor(0, 1);
          lcd1.print("Zunaj:");
          lcd1.setCursor(14, 1);
          lcd1.print(value2, 2); //
        }
        else
        {
          Serial.println(F("bad Zunaj value"));
        }
      }

      if (finder.find("Garaza:")) {
        float finderValue = finder.getFloat(".")
        if(finderValue != -127 or finderValue != 85)
        {
          value3 = finderValue;
          Serial.println();
          Serial.println("Garaza:");
          Serial.print(value3);
          Serial.print(" C");
          lcd1.setCursor(0, 2);
          lcd1.print("Garaza:");
          lcd1.setCursor(14, 2);
          lcd1.print(value3, 2); //
        }
        else
        {
          Serial.println(F("bad Garaza value"));
        }
      }
      Serial.println();
      Serial.print("prejšnje vrednosti");
      Serial.println();
      Serial.print(lastvalue1);
      Serial.println();
      Serial.print(lastvalue2);
      Serial.println();
      Serial.print(lastvalue3);
      Serial.println();
//      lastvalue1 = value1;
//      lastvalue2 = value2;
//      lastvalue3 = value3;
      counter = counter + 1;
      Serial.println();
      Serial.println("Counter of readings:");
      Serial.print(counter);
      Serial.println();

    }


    delay(10000); // check again in 10 seconds

  }

  client.stop();

}

I believe. You guys are professionals I'm a beginner :confused:
Here is example of my graph,and almost finished project....

A wood stove

svedr:
I believe. You guys are professionals I'm a beginner :confused:

but your build is professional... very nice!

THANK YOU :smiley:

Somehow I solve the problem with I2C long line (30m) - In each apartment one screen and finish.
Now i use another arduino to read value from web, but in case No electricity ( in winters sometimes a lot of snow and ice ) my web reading does not help me. (The boiler room has its own power supply from UPS)

Regards