Hello everybody.
I’m trying to initialize the rtc of MKR1000 as described in the WifiRTC sample code, but it seems that the WiFi.getTime() function doesn’t workproperly.
The following fragment of code gives always the “NTP ureachable” message.
int InitRtcWithNTP(void)
{
unsigned long ulEpoch;
int iNumberOfTries = 0, iMaxTries = 6;
do
{
ulEpoch = WiFi.getTime();
iNumberOfTries++;
}
while ((ulEpoch == 0) && (iNumberOfTries < iMaxTries));
if (iNumberOfTries >= iMaxTries)
{
PRINTLN(“NTP unreachable!!”);
return 1;
}
PRINT("Epoch received: ");
PRINTLN(ulEpoch);
MyRtc.setEpoch(ulEpoch);
return 0;
}
I’ve checked that arduino can reach internet, resolve addresses and successfully ping an host on internet both using the name and the address.
I’ve checked also that from inside my home network the ntpservers are reachable (I’ve tried with a NTP query tool to query a server at us.pool.ntp.org).
Is there a problem in my code, in the library or where else?
I’m using IDE 1.8.8 with WiFi101ver. 0.15.3.
Did anyone had the same problem?
I’m looking forward to receive suggestions.