Page 1 of 1

NTP issue(2036)

Posted: Tue Dec 10, 2019 10:07 am
by somesh
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.

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.

Re: NTP issue(2036)

Posted: Wed Dec 11, 2019 2:12 am
by ESP_Sprite
Note: you may be better off creating a new issue on Github for this if you want Espressif devs to look into this.

Re: NTP issue(2036)

Posted: Wed Dec 11, 2019 5:04 am
by somesh
ESP_Sprite wrote:
Wed Dec 11, 2019 2:12 am
Note: you may be better off creating a new issue on Github for this if you want Espressif devs to look into this.
Ok. Thanks.
I have created one https://github.com/espressif/esp-idf/issues/4472.

Re: NTP issue(2036)

Posted: Wed Dec 18, 2019 12:22 pm
by somesh
Hello ESP,

Please help me for the same.
Awaiting your reply.