Send temp F to gateway only if it changes

Started by djash40, October 16, 2016, 04:58:08 PM

djash40

Okay I'm back at it with a new C++ book for Dummies. I have code that gets temperature from ds18b20 converts it to F and sends over the radio to the gateway successfully at a regular interval. Thats good but I'd like to send only IF the temperature changes and IF it remains steady to then send at a regular scheduled interval. So here is the relavant parts of code and I can't seem to make it work. Please help.  :)

//############# Begin code for temperature #########################
sensors.requestTemperatures(); 
float s4 = sensors.getTempC(watertemp); 
if (s4 > 0)
    
      {
double ptemp; // declare as double
float ctemp = sensors.getTempC(watertemp); // get temp in C
ptemp = (ctemp * (9.0 / 5.0) + 32); // convert temp C to F
dtostrf(ptemp, 3, 2, pipetemp); // convert float to String 

       }
       else
      {
Serial.println("Debug, you only see this if sensor not working!");
   
      }
//############# End code for temperature #########################

// #####################send over radio part #####################
   if (timer2 > interval2) 
   {
    
    timer2 -= interval2; //reset the timer
// byte buffLen=sprintf(buff, "node%d:%s", NODEID, pipetemp);
byte buffLen=sprintf(buff, "node%d/temperature/%s", NODEID, pipetemp);
if (radio.sendWithRetry(GATEWAYID, buff, buffLen));

 }
//######## End send over radio ########################

//##### My attempt to send or in this case test over the serial print ######
// test area

if (pipetempState != pipetemp) {
   // Print over radio if temperature changes
     
      Serial.print(pipetemp);
      Serial.println(" this is the pipetemp var");
      Serial.print(pipetempState);
      Serial.println(" this is the pipetempState var");
      Serial.print(" if you keep seeing this it didnt work");
      pipetempState=(pipetemp);
}
else
{
      Serial.println(pipetemp);
      Serial.print(" if you see this only on temp movement");
       //pipetempState=(pipetemp);
}

 //end test area 

 

djash40

I think this si going to work. Now I just have to add radio portion of code.

// new test area #######################################

   if (strcmp(pipetempState, pipetemp) == 0)  // test to see if the two strings are equal
   {
   Serial.println(" ######");
   Serial.println("Equal");
   Serial.println(pipetempState);
   Serial.println(pipetemp);
      
   }
   else
   {
    
   Serial.println(" ######");
   Serial.println("NotEqual");
   Serial.println(pipetempState);
   Serial.println(pipetemp);
   strcpy(pipetempState, pipetemp);
   
    }