1

After synchronizing time from NTP, can the time still run after the internet connection is lost? how to keep time update stored in memory without having to connect to the server after rebooting or power off? I'm using esp-idf framework.

the code is from https://github.com/espressif/esp-idf/blob/master/examples/protocols/sntp/main/sntp_example_main.c

kikicookie
  • 11
  • 1

1 Answers1

1

Memory is not the place to store the time, as memory looses it's contents when power is off. To keep track of time you need some kind if persistend storage (like EEPROM or flash) in combination with an actual clock.

Servers and end-user devices (pc, laptop, tablet, smartphone, ...) usually have a built-in hardware clock and some means to keep that clock going when the machine is switched off.

In de pc/server world this is usually the RTC (real-time clock) in combination with a battery.

In some other cases it's possible to get an add-on providing RTC+battery (see image below).

Embedded/simple devices (e.g. Arduino) may not have this and so they will loose track of time when shut down.

RTC with battery

For ESP32 it seems there are possibilities to have RTC, see for example: http://www.esp32learning.com/code/esp32-and-ds3231-rtc-example.php

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • The ESP32 could hold it's time while working/sleeping, although the internal oscillator is not very precise (max 5% error). On a custom made pcb you could add a 32kHz crystal/osc. but like you said if power is lost, the time is also. – RemyHx Aug 08 '22 at 07:40