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;
}
-
Would you please add in the (relevant bits of the) application code as well?Nick S.– Nick S.2022年07月03日 05:30:28 +00:00Commented Jul 3, 2022 at 5:30
1 Answer 1
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