Page 1 of 1

String concatenation not working

Posted: Sat Jan 31, 2015 5:30 pm
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);
  }
}

Re: String concatenation not working

Posted: Sat Jan 31, 2015 9:10 pm
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);
  }
}

Re: String concatenation not working

Posted: Sun Feb 01, 2015 5:29 am
by cosmith71
What does WiFiAlert do?

--Colin

Re: String concatenation not working

Posted: Sun Feb 01, 2015 6:11 am
by lnevo
Sends you an alert instead of waiting 5 minutes from the portal.

Re: String concatenation not working

Posted: Sun Feb 01, 2015 6:17 am
by cosmith71
Like an email alert?

Re: String concatenation not working

Posted: Sun Feb 01, 2015 6:29 am
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);
  }
}

Re: String concatenation not working

Posted: Wed Feb 04, 2015 4:14 pm
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 :)