missedUpdates
This commit is contained in:
parent
dfce60e01f
commit
b3b1908480
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t seconds;
|
uint64_t seconds;
|
||||||
|
uint32_t missedUpdates;
|
||||||
bool valid;
|
bool valid;
|
||||||
} t_seconds;
|
} t_seconds;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <wizHelper.h>
|
#include <wizHelper.h>
|
||||||
|
|
||||||
|
|
||||||
static t_seconds seconds = { .seconds = 0, .valid = false };
|
static t_seconds seconds = { .seconds = 0, .missedUpdates = 0, .valid = false };
|
||||||
|
|
||||||
|
|
||||||
static void networkSecondsHandler(void *handle) {
|
static void networkSecondsHandler(void *handle) {
|
||||||
@ -20,15 +20,18 @@ static void networkSecondsHandler(void *handle) {
|
|||||||
if (tmpSeconds != 0) {
|
if (tmpSeconds != 0) {
|
||||||
coloredMsg(LOG_YELLOW, "nsh, success, time is %lu", tmpSeconds);
|
coloredMsg(LOG_YELLOW, "nsh, success, time is %lu", tmpSeconds);
|
||||||
seconds.seconds = tmpSeconds;
|
seconds.seconds = tmpSeconds;
|
||||||
|
seconds.missedUpdates = 0;
|
||||||
seconds.valid = true;
|
seconds.valid = true;
|
||||||
} else {
|
} else {
|
||||||
coloredMsg(LOG_YELLOW, "nsh, failed");
|
coloredMsg(LOG_YELLOW, "nsh, failed");
|
||||||
|
seconds.missedUpdates += 1;
|
||||||
}
|
}
|
||||||
} else if (tryAgain || ((seconds.seconds % 3600) == 0)) {
|
} else if (tryAgain || ((seconds.seconds % 3600) == 0)) {
|
||||||
coloredMsg(LOG_YELLOW, "nsh, periodically querying time");
|
coloredMsg(LOG_YELLOW, "nsh, periodically querying time");
|
||||||
uint64_t tmpSeconds = wizSntpQuery();
|
uint64_t tmpSeconds = wizSntpQuery();
|
||||||
if (tmpSeconds != 0) {
|
if (tmpSeconds != 0) {
|
||||||
coloredMsg(LOG_YELLOW, "nsh, success, network time is %lu", tmpSeconds);
|
coloredMsg(LOG_YELLOW, "nsh, success, network time is %lu", tmpSeconds);
|
||||||
|
seconds.missedUpdates = 0;
|
||||||
tryAgain = false;
|
tryAgain = false;
|
||||||
if (seconds.seconds != tmpSeconds) {
|
if (seconds.seconds != tmpSeconds) {
|
||||||
coloredMsg(LOG_YELLOW, "nsh, local time updated");
|
coloredMsg(LOG_YELLOW, "nsh, local time updated");
|
||||||
@ -38,6 +41,7 @@ static void networkSecondsHandler(void *handle) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
coloredMsg(LOG_YELLOW, "nsh, failed, trying again ...");
|
coloredMsg(LOG_YELLOW, "nsh, failed, trying again ...");
|
||||||
|
seconds.missedUpdates += 1;
|
||||||
tryAgain = true;
|
tryAgain = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,6 @@ bool wizDnsQuery(char *name, uint8_t *ip) {
|
|||||||
uint64_t wizSntpQuery() {
|
uint64_t wizSntpQuery() {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
uint64_t seconds = 0;
|
uint64_t seconds = 0;
|
||||||
static uint32_t missedUpdates = 0;
|
|
||||||
|
|
||||||
if (networkAvailable) {
|
if (networkAvailable) {
|
||||||
coloredMsg(LOG_BLUE, "wizsq, about to call SNTP");
|
coloredMsg(LOG_BLUE, "wizsq, about to call SNTP");
|
||||||
@ -150,7 +149,6 @@ uint64_t wizSntpQuery() {
|
|||||||
int8_t res = SNTP_run(&curTime);
|
int8_t res = SNTP_run(&curTime);
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
seconds = curTime.seconds - UNIX_NTP_EPOCH_DIFF;
|
seconds = curTime.seconds - UNIX_NTP_EPOCH_DIFF;
|
||||||
missedUpdates = 0;
|
|
||||||
updated = true;
|
updated = true;
|
||||||
success = true;
|
success = true;
|
||||||
coloredMsg(LOG_BLUE, "wizsq, curTime: %lu", seconds);
|
coloredMsg(LOG_BLUE, "wizsq, curTime: %lu", seconds);
|
||||||
@ -160,11 +158,9 @@ uint64_t wizSntpQuery() {
|
|||||||
|
|
||||||
if (! updated) {
|
if (! updated) {
|
||||||
coloredMsg(LOG_BLUE, "wizsq, time update failed");
|
coloredMsg(LOG_BLUE, "wizsq, time update failed");
|
||||||
missedUpdates += 1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
coloredMsg(LOG_BLUE, "wizsq, error when querying ntp server name");
|
coloredMsg(LOG_BLUE, "wizsq, error when querying ntp server name");
|
||||||
missedUpdates += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user