This commit is contained in:
Wolfgang Hottgenroth 2021-02-07 14:14:54 +01:00
parent be279e4421
commit 5b767535f6
2 changed files with 15 additions and 13 deletions

View File

@ -5,11 +5,11 @@
#include <stdint.h>
#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_
#endif // _WIZHELPER_H_

View File

@ -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;