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