Code issue i can not find

hello,

i calculate a ratio, and if the value change more than 3%, i publish it to google ( sub program ), and update the data last_ratio. ( last one saved )

for an unknown reason, the code is not working one way… only one test is working.

Any idea ?

what would be the best way / code to do this, meaning detect a value change more than xx %

thanks in advance.

Franck

//===================================== 
//=== test if ratio changed ===========
//=====================================
 void ratio_change() {
   //========   
   min_temp=last_ratio*0,97;
   if ( ratio < min_temp ) {
      pubgoogle;
  
      last_ratio=ratio;
      return;
   }
  
   //======  
   max_temp=last_ratio*1,03;
   if ( ratio > max_temp) {
       pubgoogle;
  
       last_ratio=ratio;
   }
}

Are you sure this even compiles?

You are using the comma (,) where you’d need to use the decimal dot (.) in 0.97 & 1.03.
And pubgoogle; is not a function call.

You can write this slightly different

bool ration_change() {
  // when ratio is outside of interval 
  if ( ratio < last_ratio * 0.97 || last_ratio * 1.03 < ratio ) {
    pubgoogle();
    last_ratio = ratio;
  }
}
1 Like

hello ScruffR,

thanks a lot for your help, what a stupid mistake a could not see… comma ( , . ).

i fixed it and it work.

i also like your all in one test.

The Pubgoogle() is a fonction that pushed data to google, using spark.publish, with delimiter, then I used cloud function to push data to big query.

see extract of the function.

 String text6=String(volt,0); // Vin monitoring without the . so divided by 100 

 text0 = text1+';'+text2+';'+text3+';'+text4+';'+text5+';'+text6+';'+text7+';'+text8+';'+text9+';'+text10;
       
        Spark.publish("DATA ",text0,60,PRIVATE);

thanks a lot for your help.

"Spark" is ancient by now. You'd do well to update it to Particle, as it's written in the docs.

thank you,

i will update… as you can see it’s now a long time i am with particle …

thank you