NTP issue(2036)
Posted: Tue Dec 10, 2019 10:07 am
Hello,
I am using esp idf v3.3 and trying to get time from ntp server( asia.pool.ntp.org ). but sometimes I am getting wrong time from ntp server i.e. 07/02/2036. after doing R&D into this, I found that where there is no response from NTP server time is set to year 2036.
Please check following link for your reference.
https://github.com/gmag11/NtpClient/issues/70
I am using following sample code to resolve. please check for the same and let me know how to handle such problem.
we can handle it by checking year but not looks like its good solution. please suggest.
I am using esp idf v3.3 and trying to get time from ntp server( asia.pool.ntp.org ). but sometimes I am getting wrong time from ntp server i.e. 07/02/2036. after doing R&D into this, I found that where there is no response from NTP server time is set to year 2036.
Please check following link for your reference.
https://github.com/gmag11/NtpClient/issues/70
I am using following sample code to resolve. please check for the same and let me know how to handle such problem.
Code: Select all
void get_time() {
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0,"asia.pool.ntp.org");
sntp_init();
time_t now;
struct tm timeinfo;
time(&now);
setenv("TZ", "UTC-05:30", 1);
tzset();
localtime_r(&now, &timeinfo);
while( timeinfo.tm_year <= 70 )
{
time(&now);
localtime_r(&now, &timeinfo);
ESP_LOGI(TAG, "Trying to reach NTP server...");
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
strftime(Timebuffer, sizeof(Timebuffer), "%d-%m-%Y %T", &timeinfo);
ESP_LOGI(TAG, "The current date/time is: %s", Timebuffer);
}
we can handle it by checking year but not looks like its good solution. please suggest.