diff --git a/cube/User/Inc/wizHelper.h b/cube/User/Inc/wizHelper.h index e1c6b92..9e10d5c 100644 --- a/cube/User/Inc/wizHelper.h +++ b/cube/User/Inc/wizHelper.h @@ -5,11 +5,11 @@ #include -#define NTP_SERVER "0.pool.ntp.org" +#define NTP_SERVER "0.de.pool.ntp.org" int wizInit(); bool isNetworkAvailable(); uint8_t* wizGetIPAddress(); bool wizDnsQuery(char *name, uint8_t *ip); -#endif // _WIZHELPER_H_ \ No newline at end of file +#endif // _WIZHELPER_H_ diff --git a/cube/User/Src/wizHelper.c b/cube/User/Src/wizHelper.c index ffcbc7b..3a076b0 100644 --- a/cube/User/Src/wizHelper.c +++ b/cube/User/Src/wizHelper.c @@ -137,17 +137,19 @@ static void wizSNTPHandler(void *handle) { if (networkAvailable) { coloredMsg(LOG_BLUE, "wizsh, about to call SNTP"); + uint8_t ntpServer[4]; - if (wizDnsQuery(NTP_SERVER, &ntpServer)) { - SNTP_init(SNTP_SOCK, NTP_SERVER, 0, sntpBuffer); - int8_t res = SNTP_run(&curTime); - coloredMsg(LOG_BLUE, "wizsh, res: %d", res); - if (res == 1) { - coloredMsg(LOG_BLUE, "wizsh, curTime: %04d-%02d-%02d %02d:%02d:%02d", - curTime.yy, curTime.mo, curTime.dd, - curTime.hh, curTime.mm, curTime.ss); - } else { - coloredMsg(LOG_BLUE, "wizsh, error when requesting time"); + if (wizDnsQuery(NTP_SERVER, ntpServer)) { + SNTP_init(SNTP_SOCK, ntpServer, 0, sntpBuffer); + for (uint8_t i = 0; i < 16; i++) { + int8_t res = SNTP_run(&curTime); + coloredMsg(LOG_BLUE, "wizsh, res: %d", res); + if (res == 1) { + coloredMsg(LOG_BLUE, "wizsh, curTime: %04d-%02d-%02d %02d:%02d:%02d", + curTime.yy, curTime.mo, curTime.dd, + curTime.hh, curTime.mm, curTime.ss); + break; + } } } else { coloredMsg(LOG_BLUE, "wizsh, error when querying ntp server name"); @@ -185,7 +187,7 @@ static void wizPhyLinkHandler(void *handle) { dhcpInitialized = true; - schAdd(wizSNTPHandler, NULL, 0, 60*1000); + schAdd(wizSNTPHandler, NULL, 0, 10*1000); coloredMsg(LOG_BLUE, "wizplh, SNTP handler scheduled"); sntpInitialized = true;