ESP32 NTP issue

snakescb
Posts: 1
Joined: Mon Apr 29, 2019 10:19 pm

ESP32 NTP issue

Postby snakescb » Mon Apr 29, 2019 10:32 pm

Dear all,
I have an issue that drives me crazy, hope somebody can help me. I have a running project with an ESP32, where the ESP32 is in deep sleep most of the time and wakes up every minute or so to do something. Every 10th wakeup, or after around 10 minutes, it is connecting to WIFI and passing some data to a server.

Now, when connected to WIFI, I want to readjust my RTC by NTC. After 10 mintes my time drifted for some seconds, no big deal, as I have a WIFI connection I just can reajust. But, the time is never updated. It updates only after a power on reset, but never after a deep sleep. Any idea? Below the code which is updating the clock. It always says "Done", but actually the rtc is never adjused.

Thank you for your help.
Christian

Code: Select all

#define TIMEZONE  "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"
#define NTPSERVER "ch.pool.ntp.org"

bool updateServer(void) {
  if (connectWifi()) {

    //Update RTC
    Serial.println("Downloading time from NTP server now... ");
    configTzTime(TIMEZONE, NTPSERVER);
    
    struct tm timeInfo;
    if (getLocalTime(&timeInfo, 10000)) {
      Serial.println(&timeInfo, "Done: %A, %B %d %Y %H:%M:%S");
    }
    else Serial.println("Error. Unable to download time from NTP server.");

    //Finish
    WiFi.disconnect(true);
    WiFi.mode(WIFI_OFF);
    return true;

  }
  else Serial.println("Error, cannot connect to WIFI. Sorry.");

  return false;
}

Who is online

Users browsing this forum: Baidu [Spider], VladTheImpaler and 5 guests