gmag11 / ESPNtpClient

High accuracy NTP library for ESP32 and ESP8266
MIT License
118 stars 25 forks source link

Clarification #42

Closed guestisp closed 2 years ago

guestisp commented 2 years ago

Ciao, simple question: syncing from NTP automatically syncs the ESP32 internal clock ? Any further requests to NTP.getTimeDateString() or NTP.getTimeString() are done from the internal clock without usingn network, right ? In other words , after the first sync, the network is not required anymore (except for the scheduled ntp syncs)

Do you know how to update the DS3231 RTC ? I'm trying to use ntp as the initial sync, then update an RTC to keep the time updated even when powered off

gmag11 commented 2 years ago

You are right. The intention of this lib is to sync internal IDF clock. Notice that, unless you need very high precision, this library is redundant as IDF already has an internal SNTP client.

You can configure it as simple as adding this to your setup() function:

sntp_setservername (0, "pool.ntp.org");
setenv ("TZ", PSTR ("CET-1CEST,M3.5.0,M10.5.0/3"), 1); //set your time zone
tzset ();
sntp_init ();

In order to set any RTC you can use a sync event callback. Both EspNtpClient library and internal SNTP IDF client have their own event callbacks.