Non-monotonic clock when rebooting with no internet access
Posted: 24 Mar 2021, 23:40
We are using a RevPi on a product and we do not always have access to the internet. We are finding that when the RevPi is restarted it sets the clock to the last time it had access to the internet. This results in time “going backwards”
An example will help:
2/1/2021 - RevPi is on and has internet connectivity. Time is set correctly.
2/1 -3/1: RevPi is unpowered and shipped to customer
3/1: RevPi is turned on but has no internet access. Date is set to 2/1/2021. While the clock is not correct it continues to move forward and files written on this date appear after files written prior to this date.
3/1-3/2: The RevPi is continuously powered for 48 hours. Clock advances. Time is off by a month but continues to move forward.
3/3: RevPi is rebooted.
-- Prior to rebooting the clock thinks the date is 2/3/2021.
-- After rebooting the clock is set to 2/1/2021. Files written just before rebooting will appear to be 2 days in the future.
Clearly the RevPi records the time to a file while it is synced with NTP. This allows the Pi to boot a month later and still have the date/time advance forward from the last time the system was operating.
Is there a way to tell the Pi to periodically update the time in this file, even when not synced with NTP, such that time never appears to go backwards, even when there is no internet?
More generally, is there a way to ensure that upon booting the clock never moves backwards. (To be reasonable let's say never moves backwards more than 5 minutes.)
If anyone can recommend an RTC module that plugs into the Pi we would welcome that solution too.
Thank you,
Andy
An example will help:
2/1/2021 - RevPi is on and has internet connectivity. Time is set correctly.
2/1 -3/1: RevPi is unpowered and shipped to customer
3/1: RevPi is turned on but has no internet access. Date is set to 2/1/2021. While the clock is not correct it continues to move forward and files written on this date appear after files written prior to this date.
3/1-3/2: The RevPi is continuously powered for 48 hours. Clock advances. Time is off by a month but continues to move forward.
3/3: RevPi is rebooted.
-- Prior to rebooting the clock thinks the date is 2/3/2021.
-- After rebooting the clock is set to 2/1/2021. Files written just before rebooting will appear to be 2 days in the future.
Clearly the RevPi records the time to a file while it is synced with NTP. This allows the Pi to boot a month later and still have the date/time advance forward from the last time the system was operating.
Is there a way to tell the Pi to periodically update the time in this file, even when not synced with NTP, such that time never appears to go backwards, even when there is no internet?
More generally, is there a way to ensure that upon booting the clock never moves backwards. (To be reasonable let's say never moves backwards more than 5 minutes.)
If anyone can recommend an RTC module that plugs into the Pi we would welcome that solution too.
Thank you,
Andy