Restore RTC value after Pysense go_to_sleep

  • In I am using rtc.ntp_sync to set up automatic fetch. If I put Pysense to sleep, I lose the automatic datetime info after it wakes up.

    Is there any way to restore RTC value without having to start the whole process of connecting to WiFi and syncing again?

    I am using Lopy4 + Pysense

  • @gabrielapb You could try the following:

    • save the current timestamp to NVS before going to sleep
    • on wake-up:
      • retrieve the saved timestamp from NVS
      • retrieve the "remaining sleep" from the Pysense using pysense.get_sleep_remaining
      • current timestamp is approximately saved + sleep interval - remaining

    Note this won't get you a very precise time (as it doesn't take into account boot time, and I'm not sure of the accuracy of the Pysense clock), and the offset to the real time will increase with the number of sleep periods, but it's helpful to have at least of rough idea of the time until you can get the actual time through other means.

    The alternative is to use the module's deep sleep rather than the Pysense's deep sleep, but that may not be possible depending on your actual use case.

Pycom on Twitter