Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 1 month ago.
NTPClient reads Fri 01-Jan-2066 02:00:00
NTPClient reads Fri 01-Jan-2066 02:00:00 (or 00:00:00), or it hangs reading the time.
Reading time: [NTPClient : DBG]Time is set to (UTC): Fri Jan 1 00:00:00 2066 [NTPClient : DBG]Binding socket [NTPClient : DBG]Ping [NTPClient : DBG]Pong
I use cc3000 on DISCO-F746NG. From the laptop, I can ping the NTP server, and I tried to retrieve the time from several NTP servers, with no luck.
It appears if DUBUG is enabled it never hangs, but comes with a wrong date and time. If it is disabled, it often hangs.
What could be the problem?
// Read time from server
NTPClient ntp_client;
// NTP Server Parameters
// char* domain_name = "217.114.59.3";
char* domain_name = "2.nl.pool.ntp.org";
// char* domain_name = "0.uk.pool.ntp.org";
int port_number = 123;
time_t ct_time;
char time_buffer[80];
char time_buffer_old[80];
printf("Reading time: ");
if (ntp_client.setTime(domain_name, port_number) == 0) {
printf("Passed.\r\n");
ct_time = time(NULL) + 7200; // Summer time - Convert to Europe/Amsterdam Time
set_time(ct_time);
strftime(time_buffer, 80, "%a %d-%b-%Y %T", localtime(&ct_time));
printf("Time : %s\r\n", time_buffer);
} else {
printf("FAILED!\r\n");
}