0

After HW reset (button or power reconnect) I get the correct NTP shift, but when I use ESP.restart() via MQTT I get the correct time without 3 3 HRS shift due to Tz. What happens after SW reset that behaves in such manner and how to fix it?

bool myIOT2::_startNTP(const char *ntpServer, const char *ntpServer2)
{
    unsigned long startLoop = millis();
    while (!_NTP_updated() && (millis() - startLoop < 20000))
    {
#if defined(ESP8266)
        configTime(TZ_Asia_Jerusalem, ntpServer2, ntpServer); // configuring time offset and an NTP server
#elif defined(ESP32)
        configTzTime(TZ_Asia_Jerusalem, ntpServer2, ntpServer);
#endif
        delay(1000);
    }
    if (!_NTP_updated())
    {
        return 0;
    }
    else
    {
        return 1;
    }
}
bool myIOT2::_NTP_updated()
{
    return now() > 1640803233;
}
guyd
  • 1,049
  • 2
  • 26
  • 61

1 Answers1

0

Apparently, time in ESP32 survives a sw reset, while in ESP8266 doesn't. So in code, which is same for both - if clock is updated (a rough criteria that time is greater than some day in 2020 ), it skipped TZ update configTzTime(TZ_Asia_Jerusalem, ntpServer2, ntpServer);

So after a crash and/or sending a MQTT message to reboot, time was missing TZ update.

Hope it'll help someone.

Guy

guyd
  • 1,049
  • 2
  • 26
  • 61