Argon crashes when using using Time

I have a setup where I am using the Time function to get a timestamp that I am using as part of a message payload to send over MQTT.

For example:

timeStr = Time.format(Time.now(), TIME_FORMAT_ISO8601_FULL);
    
if (client.isConnected()) 
{ 
    sprintf(publishString,"[{\"device\": %s, \"timestamp\": %s, \"temperature\": %d}]",macAddr.c_str(),timeStr.c_str(),temp);
    client.publish("outTopic/temperature", publishString, MQTT::QOS0);
}

If I comment out the use of the Time function, it works fine. If I leave that in, it runs once and then the Argon flashes red and reboots.

I tried a couple of other ntp libraries and saw the same issue.

Any ideas why using time/ntp functions would do this?

You may want to use snprintf() instead of sprintf() to ensure that you are not overshooting the length of your publishString.

How long have you publishString defined?

BTW, when you see red blinks it’s always good to also state how that looks.
I’d expect it to be an SOS + 1

2 Likes

OMG…I cannot believe it was that simple. You called it - I was overshooting publishString.

Thanks!!!

1 Like