Closed Yhaw closed 9 months ago
The ESP32 platform API configTime() will periodically sync the internal clock with the STNP server. Unless you use an external crystal, the, the build in oscillator is not very accurate and will cause a clock drift.
Your implementation would need to be periodically call a STNP server to keep the clock in sync.
After inserting the keys and the device Id with all necessary information in the IoT hub or Central example for ESP32, once I upload the to esp32 board, it asks to sync the board with an SNTP server but after going through this process for sometime , it gets stuck in a loop.
The log output I get is "SETTING TIME SNTP .........................................................................."
once the board gets started and connects with the wifi, it trys connect to the server and this happens.
I am assuming the problem is the domain to the SNTP servers, they may not be working or so.
define NTP_SERVERS "pool.ntp.org", "time.nist.gov"
But I found a way around! So I decide to use a different sntp server api, do a little changes to the initialize time function and it worked this is the code
this is the new changes
define NTP_SERVERS "http://worldtimeapi.org/api/timezone/Etc/UTC"
static void initializeTime() {
Logger.Info("Setting time using Time API");
HTTPClient http; http.begin(NTP_SERVERS); int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) { String payload = http.getString();
} else { Serial.print("HTTP error code: "); Serial.println(httpCode); }
http.end();
delay(1000); }
And this worked for me.
Thank you