String concatenation not working

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

String concatenation not working

Post by lnevo »

Hey guys,

I'm trying to add a daily report sent out from my RA twice a day with Temp/PH and WL %... I think I'm doing something wrong with the sprintf. When I had the variables passed directly it through my RA into crazy ass mode and all different ports were going off. When I tried dereferencing & or using the pointer * it was just getting 0 in the values. So, not sure what I'm doing wrong...

Anyway, here's the function:

Code: Select all

void DailyReport() { 
  static WiFiAlert dailyReport;
  char temp[4];
  char ph[4];
  char wl[3];
  char msg[32];    

 if (now()%(12*SECS_PER_HOUR)+(6*SECS_PER_HOUR)==0) {
    ConvertNumToString(temp, ReefAngel.Params.Temp[T1_PROBE], 10);
    ConvertNumToString(ph, ReefAngel.Params.PH, 100);
    ConvertNumToString(wl, ReefAngel.WaterLevel.GetLevel(), 1);
    sprintf(msg,"Temp:+%s+PH:+%s+WL:+%s%",&temp,&ph,&wl);
    dailyReport.Send(msg);
  }
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: String concatenation not working

Post by rimai »

Try this:

Code: Select all

void DailyReport() { 
  static WiFiAlert dailyReport;
  char msg[32];    
  char temp[10];
  char ph[10];

  if (now()%(12*SECS_PER_HOUR)+(6*SECS_PER_HOUR)==0) {
    dtostrf((float)ReefAngel.Params.Temp[T1_PROBE]/10,3, 1, temp);
    dtostrf((float)ReefAngel.Params.PH/100,4, 2, ph);
    sprintf(msg,"Temp: %s\nPH: %s\nWL: %d",temp,ph,ReefAngel.WaterLevel.GetLevel());
    dailyReport.Send(msg);
  }
}
Roberto.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: String concatenation not working

Post by cosmith71 »

What does WiFiAlert do?

--Colin
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: String concatenation not working

Post by lnevo »

Sends you an alert instead of waiting 5 minutes from the portal.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: String concatenation not working

Post by cosmith71 »

Like an email alert?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: String concatenation not working

Post by lnevo »

Yep. But one you can trigger and send whatever you like. There's a built-in 15 minute delay between each Send executing. But you can adjust it with WiFiAlert::SetDelay(byte minute)

Anyway, the timing code wasn't working properly. I think I got it now, here's the final function:

Code: Select all

void DailyReport() { 
  static WiFiAlert dailyReport;
  char msg[32];    
  char temp[10];
  char ph[10];

  if ((now()+(6*SECS_PER_HOUR))%(12*SECS_PER_HOUR)==0) {
    dtostrf((float)ReefAngel.Params.Temp[T1_PROBE]/10,3, 1, temp);
    dtostrf((float)ReefAngel.Params.PH/100,4, 2, ph);
    sprintf(msg,"Temp:+%s+PH:+%s+WL:+%d",temp,ph,ReefAngel.WaterLevel.GetLevel());
    dailyReport.Send(msg);
  }
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: String concatenation not working

Post by lnevo »

Have to say this minor and easy addition is awesome. My tank runs so smoothly and I rely on the alerts so much having a daily ping with my stats is awesome. The first one comes right before I wake up so if any issue I know about it before work. The second one comes on my train ride home. Very nice :)
Post Reply