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;
}
asked Jul 2, 2022 at 13:40
1
  • Would you please add in the (relevant bits of the) application code as well? Commented Jul 3, 2022 at 5:30

1 Answer 1

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

answered Aug 15, 2022 at 19:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.