Hi All,
I am in the process of converting all my String formats, which I use for publish strings, to snprintf in an attempt to optimise my code. I have a function that sends up some variables using publish, one of these variables is the time stamp.
I create the timestamp like below.
const char* timeStamp = Time.format(Time.now(), "%Y-%m-%d %H:%M:%S");
Then using the following snprintf to create a publish payload.
snprintf(s, sizeof(s), "{ \"f\": \"%.2f\", \"b\": \"%.2f\", \"t\": \"%s\", \"s\": \"%d\", \"Em\": \"%s\", \"r\": \"%d\", \"sd\": \"%d\"}", Freq, batt, timeStamp, bars, Em,reset,SD);
Now the weird thing is that when this code runs just after startup I get 3 garbage symbols as output, whereas when the same code runs 10 mins later it creates the correct Timestamp.
So I figured maybe I am calling the Time.now() to soon after connecting, so I tried the following:
if (Particle.connected()) CLOUD_HAS_CONNECTED = TRUE;
Particle.syncTime();
if(waitFor(Particle.syncTimeDone,10000)){
storeSysReadings(!useSD,resetLocation); // this is the function that creates my publish payload and publishes
}
The storeSysReadings function creates the publish payload and publishes. So it should be connected with the time synced prior to sending up troublesome event. Does anyone have any idea what could be causing this? Thanks
EDIT:
I have also tried casting the Time.format with no success
const char* timeStamp = (const char*)Time.format(Time.now(), "%Y-%m-%d %H:%M:%S");