diff --git a/cube/User/Src/wizHelper.c b/cube/User/Src/wizHelper.c index 9fb41e2..ffcbc7b 100644 --- a/cube/User/Src/wizHelper.c +++ b/cube/User/Src/wizHelper.c @@ -137,14 +137,20 @@ static void wizSNTPHandler(void *handle) { if (networkAvailable) { coloredMsg(LOG_BLUE, "wizsh, about to call SNTP"); - 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); + 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"); + } } else { - coloredMsg(LOG_BLUE, "wizsh, error when requesting time"); + coloredMsg(LOG_BLUE, "wizsh, error when querying ntp server name"); } } @@ -179,7 +185,6 @@ static void wizPhyLinkHandler(void *handle) { dhcpInitialized = true; - SNTP_init(SNTP_SOCK, NTP_SERVER, 0, sntpBuffer); schAdd(wizSNTPHandler, NULL, 0, 60*1000); coloredMsg(LOG_BLUE, "wizplh, SNTP handler scheduled");