Function: Times the Spark Core began running the program is limited

Hello everybody, Sorry for my english if I made some error… (I’m French)

I’ve seen that we have a great function that allow us to check the time the Core is Up and running the program

unsigned long time = millis();

Unfortunately this function is limited by number overflow, and will reset after 49 days…
Perhaps I’ve miss something, but I didn’t find the way to have no reset of this function, Is there anybody that have find a solution?
If nothing exist, can the Spark Core team implement a function over the cloud (in minutes for example) that will not reset after 49 days?
My project is forecasted to be on air all the time (dometic communication) and I would like to monitor this time

You can fetch time via the :spark: cloud using this:

Hope it helps!

So you mean registrer the time when the Spark Core run, and see the difference with the current time? correct?
I never think about that, it could work If I take Time.Now() function, and accuracy of the result will be in second.
Thank you Kennethlimcp

I’ve write this based on @bko code monitor your core’s uptime:wink:

Did I select good datatype to keep the information as long as possible (many years)?

char uptime[64];;
int A = 0;
unsigned int upTimeSec = 0UL;
unsigned int iniTime = 0;

void setup() {
        // expose your char buffer to the Cloud API
    Spark.variable("uptime", &uptime, STRING);

void loop() {
       // register your inital runing time (only the first time)
    if (A==0){
       iniTime =;
    upTimeSec = ( - iniTime);
    unsigned min = (upTimeSec%3600)/60;
    unsigned hours = (upTimeSec%86400)/3600;
    unsigned days = (upTimeSec%2073600)/86400;
    sprintf(uptime,"{\"Days\": %u, \"Hours\": %u, \"Minutes\": %u}",days,hours,min);

1 Like

Currently, I believe the time from is a signed 32-bit integer, which means that it is subject to the Year 2038 problem. If that’s the case, you have a little less than 24 years before you’ll have any problems.

Thats enough for me considering my age :slight_smile:

I logged an issue to make return an unsigned long to avoid that bug :smile:

1 Like