[SOLVED] Reset does not pull in Time from the Cloud

My application needs correct time. The code that I have been using with the Core has the following snippet in setup():


while(Time.year() <= 1970)
{
delay(100);
}

This was previously suggested on this forum as a good way to ensure that the program doesn’t get into loop() until the Time is synced with the cloud. It has been working just fine on Cores.

I now have the program loaded on Photon and I do understand that Spark.syncTime() is not working on Photon, but that time is initialized on startup. I can confirm that time initialization from the Cloud does work if (1) you flash new firmware to the Photon, or (2) if you power up the Photon. HOWEVER, if I press the Reset button on the Photon, my program seems stuck forever in this loop(), meaning that the reset button reset does not seem to automatically sync Photon time with the cloud.

I hope that the fix for Spark.syncTime() in the next release will fix this problem as well, but I wanted to bring it to your attention.

Due to the fact that I haven't got my Photons to try it out myself yet, I have to ask stupid questions :blush:

Your code is running in default SYSTEM_MODE(AUTOMATIC)?
You haven't sent the Photon to sleep before you pressed reset?
Does your Photon ever get into breathing cyan after reset?
Can you add some debug statements before the loop (e.g. Serial.print() or Spark.function()) to check if setup() gets executed propperly up to your while()?


As for this (Edit: Just seen, you mentioned the next release already :blush:)

It's not yet working, but as I understood @mdma it will be again.

system_mode is automatic (default, never changed)
No, the Photon was not put to sleep
Yes, the Photon is breathing cyan and running setup()
There is a debug of sorts. I turn on the D7 LED before executing this code fragment and turn it off when the code fragment is done. This tells me that the time has been initialized.

When flashing new code or power cycling the Photon, the D7 LED comes on a\for a few seconds and then goes off. I know that setup() is complete and I’m running loop() because it processes data in loop and I can see it doing this. However, if the Photon is up and running, and I just press the reset button, the D7 LED comes on and never goes off (never meaning at least over several minutes). Also, no data processing is going on which says definitively that the code is stuk in loop and the LED says that it is here.

I believe that this is somehow part of the Spark.syncTime() bug with Photon that has been promised to be fixed in the next release. I posted this here in the hopes of alerting the Particle test to test this before releasing the fix.

1 Like

Is there an issue that you file on github showing this issue?

My photon automatically updates the time without me calling Spark.syncTime() and even hitting the reset button works.

I can tell as time is displayed on my lcd and it updates once the actual time is retrieved from the :cloud: :wink:

Photon does take a long time to update the clock from the cloud–at least 8-10 seconds in my experience (this is making SparkTimeAlarms not work correctly right now).

Are you waiting long enough?

Mine’s pretty speedy though… You can look out for a :spark: event publishing a “stamp” to the photon

[CLOSED]: You are all correct - this works and there is no issue. Shame on me for reporting on a sample of one try. Photon does take a LOT longer to acquire the time, but I have tried several button resets since these posts and it is working. The time that it takes to acquire an initial time is quite variable and always at least a few seconds but can be a LOT longer, either on power reset or button reset. The variability and overall long time threw me. Sorry to misreporting, but glad that there is no issue.

As far as my application is concerned, the extra time to acquire cloud time (for Photon over that for the Core) is not a big issue. That is why I use the D7 LED. If the device is reset, I can wait for the time to be set before operating but I cannot operate without the time being set because time stamping is a critical feature of this application.

Just in case someone needs it, here’s some code I use to verify that the time is set.

int particlecheckin = Time.now();
while( particlecheckin < 0 ) {
    Serial_printf("  ...delay for Cloud processing (time) %d\n",particlecheckin);
    Particle.process();
    delay(100);
    particlecheckin = Time.now();
}