I have published a library, RTC_NTP_replacement, that uses an DS3231 (Real Time Clock) as a replacement for an NTP client on an ESP32.
It has the following features:-
– Runs completely off-line, using the RTC (DS3231) to synchronize the ESP32's system clock to within a few milliseconds.
– User code uses the standard ESP32 time methods to get times and dates. The RTC is not accessed from user code.
– Provides 'smooth' synchronization of the ESP32's system clock to the RTC's time for consistent time stamps.
– Provides locally served web pages to set the time and the time zone. The web pages are formatted for easy display on a mobile phone.
– Has a time zone parser to clean up the user inputted time zone to a valid one that the ESP32 can use.
– Can optionally to use an NTP server to synchronize the RTC's date and time which then synchronizes the system time.
– Can optionally to use AsyncWebServer instead of ESP32's built in web server
In this library, the RTC's time and date is the master UTC time. Having set the RTC's time and the ESP32's time zone from the built-in web pages, the ESP32's unix time is keep in sync with the RTC's time such that the unix time never goes backwards.
If the ESP32's system time is ahead of the RTC, then the system clock is halted until the RTC catches up. If the ESP32's system time is behind the RTC's, the system time is pushed forward two seconds per second until it catches up with the RTC.