If a device is down for x hours due to power cutoff and then boots up when the power is up, it takes some minutes to get internet up and time synced with chronyc. I am using the device as a sensor data collector that marks data with a timestamp before sending it to my cloud. This introduces a wrong timestamp on the data points that are read and sent before internet connection is up. (Those messages would then have a timestamp of the device’s last boot session time+local clock time.)
What is the best way to know if the device has synced its time successfully since the last boot, and then get the difference in time and modify the wrong timestamp?
As I want to be able to buffer sensor data locally when the device is offline, choosing to wait for internet connection is not an option for me.
You can check to see whether chrony has completed it’s initial synchronisation by using the command chronyc waitsync 1. This command will return a value of 0 when chrony has synchronised. I’m not aware of any method of checking how much the time was adjusted by other than looking in the journal logs:
Nov 23 11:02:39 fc3817f chronyd[1340]: 2020-11-23T11:02:39Z System clock was stepped by 16.676809 seconds
Thanks for your answer, that seems like the best way yes. Will chrony share the same synchronisation state/time as the Host OS if chrony is installed and checked on a container?
Thanks again