How often does time sync with the cloud?

In the documentation it says:

“The device synchronizes time with the Particle Cloud during the handshake. From then, the time is continually updated on the device.”

I want to make sure I understand this correctly. I take this to mean that the Electron time syncs with the cloud during the handshake, and that this uses some small amount of data. From there you can use your time functions without using any data. When they say that " time is continually updated on the device" does that mean that it re-syncs on some regular or semi-regular basis? If so - how often? And how much data does it use when it does?

Thanks.

Hi @spork

I think you have to call Particle.syncTime() yourself periodically.

3 Likes

Interesting. I guess the part about time being continually updated on the device simply means that the Electron keeps time internally? I think I actually prefer that. I can call sync once/day or so.

Thanks.

Both the Photon and the Electron have real-time clock (RTC) sections in their processors and time is kept there. The VBAT pin or connection even allows that to keep running when powered down (but on Electron VBAT is wired to +3.3V since Electron already requires a battery).

The RTCs do not keep perfect time in my experience drifting 20-30 seconds per day for some of my devices. You can choose to sync when you need to and once a day seems fine.

3 Likes

You mean if you are manually managing your connection to the internet (particularly Electron)? Otherwise, I have clocks using Photon (permanent WiFi connection) which never make such a call and stay within a couple of seconds (as best as I can tell) accuracy.

Hi @BulldogLowell

I think the time is set whenever the cloud connection is initialized (and then whenever you call Particle.syncTime). I could not find anything in the firmware that called any of the many time-related functions on a schedule.

That said, if your Photons are taking long sleeps and then reconnecting to the cloud, that could be helping you. Or you could just have better than average crystals on your devices.

1 Like

According to the docs, syncTime is called whenever the device connects to the cloud. In my testing, I have noticed that my devices disconnect from and reconnect to the cloud multiple times per day (with the reconnect usually taking about 7 seconds). I'm not sure why this happens, and I'm still doing some testing to investigate. This happens even on a device that's running nothing but my connection logging code. If your devices are behaving similarly, this could explain your good accuracy.

1 Like

I never get that lucky...

That's my kind of luck!

Hey. I have a photon which is only connected in the local network and not on the cloud. However, I want these devices to communicate using timestamps. Is it possible to sync the time in photon without connecting to the server? Thank You.

There is this

image
on the docs page that if used will give you this

https://docs.particle.io/reference/device-os/firmware/photon/#settime-

2 Likes

That will only set the time for a particular photon at that point of time. You are assuming that all the photons in the network will update their time at the exact same time for them to be able to communicate using timestamps. That is not practical.

Even with the devices being connected to the cloud, you'd rely on the inbuilt RTC to keep the time between resyncs. Your specific need for accuracy would dictate the resync interval in either case (cloud connected or not).

You can implement a common event to tell all your devices to resync there and then.

Since you are not really disclosing a lot about your use-case it's near impossible for an outsider to assess practicability of any give solution.
It's always easy to say: "That won't do", but can you come up with a better idea?

1 Like

Pardon me if that didn't explain enough. I'll try again.
There are photons which are locally connected to wifi which does not have an active internet connection(It has a proxy which I am bypassing through a TCP client and the port 5683 can't be opened). Now, I would want these photns to include the timestamp when they are sending the data. However, due to the proxy settings they are not able to connect to the particle server where they sync their RTC. So, I would want them to somehow sync their RTC without having to connect to the particle server.
Thank You.

We understood all that already.
However, we said, you can use Time.setTime() in your code to feed any time into the onboard RTC and the devices will keep updating the time henceforth.
So in order to mimik the cloud time sync, you just need to tell all devices at once what the current time is, they all will update their local RTCs to that time almost synchronously (providing your code is written properly with minimal latency) and you'll have a fleet of time synced devices.

If you are already communicating TCP or UDP with your devices, you should know how to address all devices simultaneously :wink:

2 Likes