Setting a custom device time, without having to change SYSTEM_MODE

Hi,

Build on Photon, using Device OS 1.0.1, via IDE

I’ve been working on a custom clock, for a while, and its been a hard slog for a while, mostly to do with issues around keeping the device synced over a few days. However my issue at the moment is testing Daylight savings calculations, and I need to test how it handles my code.

I’m at the stage of testing and therefore want to intentionally set it to given time stamps, so I can check how it handle powering on and off at different times of the year and passing though the change of daylight savings…

So I am having trouble getting it to take a specific time.

I’ve written an extremley simple snippet of code to set the device to 03/30/2019 @ 11:55pm (UTC), which is 5min before midnight close to the up and comeing daylight saving event here in the new year:

//Time.setTime(1553990155);

void setup() {
Time.setTime(1553990155);

}

void loop() {

Serial.println("Date:- " + Time.timeStr());
delay(1000);

}

So it prints out the set time I want for about 5 seconds and then jumps to the real world time now.

The only way I can see to over come this is to change my SYSTEM_MODE, which is with the above code default automatic… I think… And that means rigging up an interupt button to be able switch it back to automatic to be able to OTA update my code everytime I tweek it…

So my question is… Is there an easyier way to do this? IE stop the Device OS running off and updating the device time, after I’ve preset it, without loosing other functions.

Thanks

Liam

The automatic sync happens when the device first connects to the cloud (plus a few seconds).
But once done it won’t happen again till you lose connection and reconnect again (or call Particle.syncTime()).
So you should just need to wait a few seconds till the connection was established and the auto-sync has happened and set your own time after that.
For testing you may even want to use a Particle.function() to set any arbitrary time on-the-fly.

BTW, you can’t change the SYSTEM_MODE at runtime but you don’t need to either. Once your program runs you can use Particle.disconnect() and Particle.connect() to control the cloud connection at your will.
Also no need for an interrupt, you can also poll the state of any pin and act upon that.

2 Likes

Ah, right…

So I think a 10 second pause, is the way to go. Once I’ve got my code set and tested it will be enough…

I just didn’t want to have to wait 6 months between tests… Coz I ain’t that good a coder.

And I’d really like to put this project to bed… (hanging from the celling actually…) I might even do a hackster documentation…

Once again huge thanks Scruff. Theres a reason your Elite…

Ta.

Liam

2 Likes