change schedule of sntp requests

This commit is contained in:
Wolfgang Hottgenroth 2021-02-08 12:29:21 +01:00
parent 95f40065f3
commit ddc62e7e29
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -136,6 +136,8 @@ bool wizDnsQuery(char *name, uint8_t *ip) {
static void wizSNTPHandler(void *handle) {
bool success = false;
if (networkAvailable) {
coloredMsg(LOG_BLUE, "wizsh, about to call SNTP");
@ -159,7 +161,9 @@ static void wizSNTPHandler(void *handle) {
seconds.valid = true;
seconds.missedUpdates = 0;
updated = true;
success = true;
coloredMsg(LOG_BLUE, "wizsh, curTime: %lu", seconds.seconds);
break;
}
}
@ -172,8 +176,10 @@ static void wizSNTPHandler(void *handle) {
seconds.missedUpdates += 1;
coloredMsg(LOG_BLUE, "wizsh, error when querying ntp server name");
}
}
uint32_t tryAgainIn = (success) ? 60 * 1000 : 1000;
schAdd(wizSNTPHandler, NULL, tryAgainIn, 0);
}
static void wizSecondsHandler(void *handle) {
@ -213,7 +219,7 @@ static void wizPhyLinkHandler(void *handle) {
dhcpInitialized = true;
schAdd(wizSNTPHandler, NULL, 0, 60*1000);
schAdd(wizSNTPHandler, NULL, 15, 0);
coloredMsg(LOG_BLUE, "wizplh, SNTP handler scheduled");
sntpInitialized = true;
@ -236,6 +242,7 @@ static void wizPhyLinkHandler(void *handle) {
if (sntpInitialized) {
schDel(wizSNTPHandler, NULL);
coloredMsg(LOG_BLUE, "wizplh, SNTP handler unscheduled");
seconds.valid = false;
sntpInitialized = false;
}