Restore date and time after reboot

Hello Nordic Support,

I have a question regarding the real-time clock (RTC) functionality on the nRF9160.

  1. RTC availability

    • Does the nRF9160 have an internal real-time clock that can preserve time across reboots?

  2. Behavior on reboot

    • We observe that after a device reboot (without loss of power or battery), the time is reset.

    • I can understand losing time when the device is fully powered off or the battery is disconnected, but why is this happening during a reboot?

  3. Use case

    • Our firmware collects events and stores them in flash. Each event requires a timestamp.

    • Additionally, we generate JWT tokens, which also depend on accurate time.

    • In some scenarios, the device may reboot while in an area without network coverage. After the reboot, we need to continue collecting events with valid timestamps, but without network access we cannot re-sync the time.

Question:
Is there an option or recommended method to prevent the time from resetting during a reboot (e.g., preserving RTC state across soft resets), so that the device can continue operating without immediate network connectivity?

Parents
  • Hi,

     

    Does the nRF9160 have an internal real-time clock that can preserve time across reboots?

    nRF devices has a real time counter, not real time clock, unfortunately.

    I can understand losing time when the device is fully powered off or the battery is disconnected, but why is this happening during a reboot?

    All peripherals are reset on reboot, except certain functions as listed here:

    https://docs.nordicsemi.com/bundle/ps_nrf9160/page/pmureset.html#ariaid-title9

    After the reboot, we need to continue collecting events with valid timestamps, but without network access we cannot re-sync the time.

    The nRF91-device needs to fetch time from somewhere. LTE network, NTP, and/or GNSS are all options in this case.

    You mention that you store entries with timestamps:

    Our firmware collects events and stores them in flash

    You can restore the timestamp, based on the last stored entry, to get a approximation relative to the last stored timestamp. When you update the timestamp, you can compare and store the diff. This is a hack, but can give you an anchor.

    Example, use clock_settime() to restore after boot:

     Setting and Updating Absolute Time in Zephyr Application Using time_t Epoch 

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Does the nRF9160 have an internal real-time clock that can preserve time across reboots?

    nRF devices has a real time counter, not real time clock, unfortunately.

    I can understand losing time when the device is fully powered off or the battery is disconnected, but why is this happening during a reboot?

    All peripherals are reset on reboot, except certain functions as listed here:

    https://docs.nordicsemi.com/bundle/ps_nrf9160/page/pmureset.html#ariaid-title9

    After the reboot, we need to continue collecting events with valid timestamps, but without network access we cannot re-sync the time.

    The nRF91-device needs to fetch time from somewhere. LTE network, NTP, and/or GNSS are all options in this case.

    You mention that you store entries with timestamps:

    Our firmware collects events and stores them in flash

    You can restore the timestamp, based on the last stored entry, to get a approximation relative to the last stored timestamp. When you update the timestamp, you can compare and store the diff. This is a hack, but can give you an anchor.

    Example, use clock_settime() to restore after boot:

     Setting and Updating Absolute Time in Zephyr Application Using time_t Epoch 

     

    Kind regards,

    Håkon

Children
Related