SergeS
July 15, 2019, 1:17am
1
Why standard NTP-TZ-DST.ino example is not working correctly, returning January, 1, 1970?
NTP0_OR_LOCAL1 defined as 0, wifi is connected ok, internet connection is also ok.
output sample:
---8<---
clock:5/652032000ns millis:5652 micros:5652044 gtod:5/614778us time:28804 ctime:(UTC+120mn)Thu Jan 1 08:00:04 1970
clock:5/752690000ns millis:5752 micros:5752702 gtod:5/715436us time:28804 ctime:(UTC+120mn)Thu Jan 1 08:00:04 1970
clock:5/853357000ns millis:5853 micros:5853368 gtod:5/816103us time:28804 ctime:(UTC+120mn)Thu Jan 1 08:00:04 1970
clock:5/954041000ns millis:5954 micros:5954052 gtod:5/916787us time:28805 ctime:(UTC+120mn)Thu Jan 1 08:00:05 1970
---8<---
p.s. example from here: link is working.
SergeS
July 15, 2019, 2:15am
2
Seems like I've found the problem, see below.
Here how it was in original code (in setup() ):
#else // ntp
configTime(TZ_SEC, DST_SEC, "pool.ntp.org");
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, SSIDPWD);
// don't wait, observe time changing when ntp timestamp is received
#endif // ntp
Here the problem is solved:
#else // ntp
//configTime(TZ_SEC, DST_SEC, "pool.ntp.org"); //WRONG! Call it after wifi connection
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, SSIDPWD);
// don't wait, observe time changing when ntp timestamp is received - WRONG!
//Wait for connection.
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
configTime(TZ_SEC, DST_SEC, "pool.ntp.org");
#endif // ntp