From f280fa27b53666b6d2cdc47228fcda4a4c12cdb5 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Sat, 18 Apr 2020 14:42:14 +0200 Subject: [PATCH 01/11] SNTP_fix_rtc_counter_wrapping --- extras/sntp/sntp.h | 5 -- extras/sntp/sntp_fun.c | 184 ++++++++++++++++------------------------- 2 files changed, 72 insertions(+), 117 deletions(-) diff --git a/extras/sntp/sntp.h b/extras/sntp/sntp.h index 4fde486..4e20f0c 100644 --- a/extras/sntp/sntp.h +++ b/extras/sntp/sntp.h @@ -60,11 +60,6 @@ int sntp_set_servers(const char *server_url[], int num_servers); */ void sntp_set_update_delay(uint32_t ms); -/* - * Returns the time read from RTC counter, in seconds from Epoch. If - * us is not null, it will be filled with the microseconds. - */ -time_t sntp_get_rtc_time(int32_t *us); /* * Update RTC timer. This function is called by the SNTP module each time diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index 66956ca..d73d56d 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -8,36 +8,26 @@ #include #include #include -#include #include #include #include -#include - - -#ifdef SNTP_LOGD_WITH_PRINTF -#define SNTP_LOGD(FMT, ...) printf(FMT "\n", ##__VA_ARGS__) -#endif - -#ifndef SNTP_LOGD -#define SNTP_LOGD(...) -#define SKIP_DIAGNOSTICS -#endif +#include +#include +#include +#include "sntp.h" #define TIMER_COUNT RTC.COUNTER // daylight settings // Base calculated with value obtained from NTP server (64 bits) #define sntp_base (*((uint64_t*)RTC.SCRATCH)) -// Timer value when base was obtained +// Timer value when sntp_base was obtained #define tim_ref (RTC.SCRATCH[2]) -// Calibration value -- ( microseconds / RTC tick ) * 2^12 +// Calibration value #define cal (RTC.SCRATCH[3]) -#ifndef SKIP_DIAGNOSTICS -// Keep the last time SNTP updated the time -static struct timeval last_update_time = {0, 0}; -#endif +// To protect access to the above. +static SemaphoreHandle_t sntp_sem = NULL; // Timezone related data. static struct timezone stz; @@ -48,118 +38,88 @@ void sntp_init(void); // Sets time zone. // NOTE: Settings do not take effect until SNTP time is updated. void sntp_set_timezone(const struct timezone *tz) { - if (tz) { - stz = *tz; - } else { - stz.tz_minuteswest = 0; - stz.tz_dsttime = 0; - } + if (tz) { + stz = *tz; + } else { + stz.tz_minuteswest = 0; + stz.tz_dsttime = 0; + } } // Initialization void sntp_initialize(const struct timezone *tz) { - if (tz) { - stz = *tz; - } else { - stz.tz_minuteswest = 0; - stz.tz_dsttime = 0; - } - sntp_base = 0; - // To avoid div by 0 exceptions if requesting time before SNTP config - cal = sdk_system_rtc_clock_cali_proc(); - tim_ref = TIMER_COUNT; - sntp_init(); + if (tz) { + stz = *tz; + } else { + stz.tz_minuteswest = 0; + stz.tz_dsttime = 0; + } + sntp_base = 0; + // To avoid div by 0 exceptions if requesting time before SNTP config + cal = sdk_system_rtc_clock_cali_proc(); + tim_ref = TIMER_COUNT; + sntp_sem = xSemaphoreCreateMutex(); + assert(sntp_sem == NULL); + sntp_init(); } -// Check if a timer wrap has occurred. Compensate sntp_base reference -// if affirmative. -// TODO: think about multitasking and race conditions -static inline void sntp_check_timer_wrap(uint32_t current_value) { - if (current_value < tim_ref) { - // Timer wrap has occurred, compensate by subtracting 2^32 to ref. - sntp_base -= 1LLU<<32; - // DEBUG - SNTP_LOGD("SNTP RTC counter wrapped"); - } -} +// Return usecs. +static inline uint64_t sntp_get_rtc_time() { + xSemaphoreTake(sntp_sem, portMAX_DELAY); + uint32_t tim = TIMER_COUNT; + // Assume the difference does not overflow in which case + // wrapping of the RTC timer still yields a good difference. + uint32_t diff = tim - tim_ref; + tim_ref = tim; + uint64_t diff_us = ((uint64_t)diff * cal) >> 12; + uint64_t base = sntp_base + diff_us; + sntp_base = base; + xSemaphoreGive(sntp_sem); -// Return secs. If us is not a null pointer, fill it with usecs -inline time_t sntp_get_rtc_time(int32_t *us) { - time_t secs; - uint32_t tim; - uint64_t base; - - tim = TIMER_COUNT; - // Check for timer wrap - sntp_check_timer_wrap(tim); - base = sntp_base + tim - tim_ref; - secs = (base * cal) / (1000000U<<12); - if (us) { - *us = ((base * cal) % (1000000U<<12)) >>12; - } - return secs; + return base; } // Syscall implementation. doesn't seem to use tzp. int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) { - (void)r; - // Syscall defined by xtensa newlib defines tzp as void* - // So it looks like it is not used. Also check tp is not NULL - if (tzp || !tp) return EINVAL; + (void)r; + // Syscall defined by xtensa newlib defines tzp as void* + // So it looks like it is not used. Also check tp is not NULL + if (tzp || !tp) return EINVAL; - tp->tv_sec = sntp_get_rtc_time((int32_t*)&tp->tv_usec); - return 0; + if (sntp_base == 0) { + printf("Time not valid yet"); + return EINVAL; + } + + if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) { + printf("Scheduler NOT RUNNING RHURHU"); + return EINVAL; + } + + uint64_t base = sntp_get_rtc_time(); + + tp->tv_sec = base / 1000000U; + tp->tv_usec = base % 1000000U; + return 0; } // Update RTC timer. Called by SNTP module each time it receives an update. void sntp_update_rtc(time_t t, uint32_t us) { - - uint32_t now_rtc = TIMER_COUNT; - // Apply daylight and timezone correction t += (stz.tz_minuteswest + stz.tz_dsttime * 60) * 60; + int64_t sntp_correct = (uint64_t)us + (uint64_t)t * 1000000U; -#ifndef SKIP_DIAGNOSTICS - - int64_t sntp_reference_time, local_clock_time, clock_difference; - struct timeval this_update_time, elapsed_since_update; - double ppm; - - // Calculate in diagnostics in microseconds - sntp_reference_time = (uint64_t)us + (uint64_t)t * 1000000U; - local_clock_time = ((sntp_base + now_rtc - tim_ref) * cal) / (1U<<12); - clock_difference = sntp_reference_time - local_clock_time; - - this_update_time.tv_sec = t; - this_update_time.tv_usec = us; - - timersub(&this_update_time, &last_update_time, &elapsed_since_update); - - // If over a day since last update, don't trust the last_update_time - if (elapsed_since_update.tv_sec < 24 * 60 * 60 ) { - ppm = ((double)clock_difference / - ((double)elapsed_since_update.tv_sec * 1000000 - + elapsed_since_update.tv_usec)) - * 1000000; - SNTP_LOGD("SNTP RTC adjust: %0.3Lf s; %0.3f ppm over %0.3f s; cal: %u\n", - ((long double)clock_difference)/1000000, - ppm, - (double)elapsed_since_update.tv_sec - + ((double)elapsed_since_update.tv_usec)/1000000, - cal); - } else { - SNTP_LOGD("SNTP RTC adjust: %0.3Lf s; cal: %u\n", - ((long double)clock_difference)/1000000, cal); - } - - last_update_time.tv_sec = t; - last_update_time.tv_usec = us; - -#endif // SKIP_DIAGNOSTICS - - cal = sdk_system_rtc_clock_cali_proc(); - tim_ref = now_rtc; - sntp_base = (((uint64_t)us + (uint64_t)t * 1000000U) <<12) / cal; + xSemaphoreTake(sntp_sem, portMAX_DELAY); + uint32_t tim = TIMER_COUNT; + // Assume the difference does not overflow in which case + // wrapping of the RTC timer still yields a good difference. + uint32_t diff = tim - tim_ref; + tim_ref = tim; + uint64_t diff_us = ((uint64_t)diff * cal) >> 12; + uint64_t sntp_current = sntp_base + diff_us; + sntp_base = sntp_correct; + cal = sdk_system_rtc_clock_cali_proc(); + xSemaphoreGive(sntp_sem); + printf("\nRTC Adjust: drift = %d usec, cal = %d", (int)(sntp_correct - sntp_current), cal); } - From 312073ccfdd6da5038d1873bed5415390ad564ba Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Sat, 18 Apr 2020 14:50:48 +0200 Subject: [PATCH 02/11] Revert logging --- extras/sntp/sntp_fun.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index d73d56d..b21ab48 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -16,6 +16,15 @@ #include #include "sntp.h" +#ifdef SNTP_LOGD_WITH_PRINTF +#define SNTP_LOGD(FMT, ...) printf(FMT "\n", ##__VA_ARGS__) +#endif + +#ifndef SNTP_LOGD +#define SNTP_LOGD(...) +#define SKIP_DIAGNOSTICS +#endif + #define TIMER_COUNT RTC.COUNTER // daylight settings @@ -26,6 +35,11 @@ // Calibration value #define cal (RTC.SCRATCH[3]) +#ifndef SKIP_DIAGNOSTICS +// Keep the last time SNTP updated the time +static struct timeval last_update_time = {0, 0}; +#endif + // To protect access to the above. static SemaphoreHandle_t sntp_sem = NULL; @@ -91,11 +105,6 @@ int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) { return EINVAL; } - if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) { - printf("Scheduler NOT RUNNING RHURHU"); - return EINVAL; - } - uint64_t base = sntp_get_rtc_time(); tp->tv_sec = base / 1000000U; @@ -121,5 +130,5 @@ void sntp_update_rtc(time_t t, uint32_t us) { cal = sdk_system_rtc_clock_cali_proc(); xSemaphoreGive(sntp_sem); - printf("\nRTC Adjust: drift = %d usec, cal = %d", (int)(sntp_correct - sntp_current), cal); + SNTP_LOGD("SNTP RTC Adjust: drift = %d usec, cal = %d", (int)(sntp_correct - sntp_current), cal); } From c97ef10267a46839fdf883b93980587cde5bc70f Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Sat, 18 Apr 2020 15:29:50 +0200 Subject: [PATCH 03/11] fix build warning --- extras/sntp/sntp_fun.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index b21ab48..b4210ec 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -35,11 +35,6 @@ // Calibration value #define cal (RTC.SCRATCH[3]) -#ifndef SKIP_DIAGNOSTICS -// Keep the last time SNTP updated the time -static struct timeval last_update_time = {0, 0}; -#endif - // To protect access to the above. static SemaphoreHandle_t sntp_sem = NULL; @@ -70,10 +65,11 @@ void sntp_initialize(const struct timezone *tz) { } sntp_base = 0; // To avoid div by 0 exceptions if requesting time before SNTP config - cal = sdk_system_rtc_clock_cali_proc(); + cal = 1; tim_ref = TIMER_COUNT; sntp_sem = xSemaphoreCreateMutex(); assert(sntp_sem == NULL); + sntp_init(); } @@ -120,13 +116,15 @@ void sntp_update_rtc(time_t t, uint32_t us) { xSemaphoreTake(sntp_sem, portMAX_DELAY); uint32_t tim = TIMER_COUNT; + tim_ref = tim; + sntp_base = sntp_correct; +#ifndef SKIP_DIAGNOSTICS // Assume the difference does not overflow in which case // wrapping of the RTC timer still yields a good difference. uint32_t diff = tim - tim_ref; - tim_ref = tim; uint64_t diff_us = ((uint64_t)diff * cal) >> 12; uint64_t sntp_current = sntp_base + diff_us; - sntp_base = sntp_correct; +#endif cal = sdk_system_rtc_clock_cali_proc(); xSemaphoreGive(sntp_sem); From e7a95326d392646a781a39634e3349211f033a88 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Sat, 18 Apr 2020 20:02:27 +0200 Subject: [PATCH 04/11] Added the ESP-wifi-config submodule to the ESP-RTOS and also add a example --- .gitmodules | 3 +++ examples/wifi-config-v2/Makefile | 18 ++++++++++++++++++ examples/wifi-config-v2/main.c | 19 +++++++++++++++++++ extras/wifi-config-v2 | 1 + 4 files changed, 41 insertions(+) create mode 100644 examples/wifi-config-v2/Makefile create mode 100644 examples/wifi-config-v2/main.c create mode 160000 extras/wifi-config-v2 diff --git a/.gitmodules b/.gitmodules index 5647056..0e153bd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,3 +46,6 @@ [submodule "lvgl/lv_examples"] path = lvgl/lv_examples url = https://github.com/littlevgl/lv_examples.git +[submodule "extras/wifi-config-v2"] + path = extras/wifi-config-v2 + url = https://github.com/maximkulkin/esp-wifi-config.git diff --git a/examples/wifi-config-v2/Makefile b/examples/wifi-config-v2/Makefile new file mode 100644 index 0000000..7d82827 --- /dev/null +++ b/examples/wifi-config-v2/Makefile @@ -0,0 +1,18 @@ +# Makefile for wificfg example +PROGRAM=wifi-config-v2 +EXTRA_COMPONENTS=extras/wifi-config-v2 extras/http-parser extras/dhcpserver + +# For the mDNS responder included under extras: +#EXTRA_COMPONENTS += extras/mdnsresponder +#EXTRA_CFLAGS += -DEXTRAS_MDNS_RESPONDER + +# For the mDNS responder included with lwip: +EXTRA_CFLAGS += -DLWIP_MDNS_RESPONDER=1 -DLWIP_NUM_NETIF_CLIENT_DATA=1 -DLWIP_NETIF_EXT_STATUS_CALLBACK=1 + +# Avoid writing the wifi state to flash when using wificfg. +EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0 + +# enable debugging for the wifi config tasks +EXTRA_CFLAGS += -DWIFI_CONFIG_DEBUG + +include ../../common.mk diff --git a/examples/wifi-config-v2/main.c b/examples/wifi-config-v2/main.c new file mode 100644 index 0000000..17392f9 --- /dev/null +++ b/examples/wifi-config-v2/main.c @@ -0,0 +1,19 @@ +#include +#include + +#include "wifi_config.h" + + +void on_wifi_event(wifi_config_event_t event) { + if (event == WIFI_CONFIG_CONNECTED) { + printf("Connected to WiFi\n"); + } else if (event == WIFI_CONFIG_DISCONNECTED) { + printf("Disconnected from WiFi\n"); + } +} + +void user_init(void) { + uart_set_baud(0, 115200); + + wifi_config_init2("my-accessory", NULL, on_wifi_event); +} \ No newline at end of file diff --git a/extras/wifi-config-v2 b/extras/wifi-config-v2 new file mode 160000 index 0000000..0b385c6 --- /dev/null +++ b/extras/wifi-config-v2 @@ -0,0 +1 @@ +Subproject commit 0b385c69a001db475e8152080f33c8afa0395784 From cf461bfa1dded86c8b1e19df6efee71a2c4c613b Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Mon, 20 Apr 2020 08:26:55 +0200 Subject: [PATCH 05/11] Fix assert statement --- extras/sntp/sntp_fun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index b4210ec..12e986f 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -68,7 +68,7 @@ void sntp_initialize(const struct timezone *tz) { cal = 1; tim_ref = TIMER_COUNT; sntp_sem = xSemaphoreCreateMutex(); - assert(sntp_sem == NULL); + assert(sntp_sem != NULL); sntp_init(); } From 3e2b2830e5abddca2412b1e52ab58310b481aed5 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Mon, 20 Apr 2020 16:54:18 +0200 Subject: [PATCH 06/11] Fixed issue in sntp, same as master --- extras/sntp/sntp_fun.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index b4210ec..d677c07 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -68,7 +68,7 @@ void sntp_initialize(const struct timezone *tz) { cal = 1; tim_ref = TIMER_COUNT; sntp_sem = xSemaphoreCreateMutex(); - assert(sntp_sem == NULL); + assert(sntp_sem != NULL); sntp_init(); } @@ -97,7 +97,7 @@ int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) { if (tzp || !tp) return EINVAL; if (sntp_base == 0) { - printf("Time not valid yet"); + printf("Time not valid yet\n"); return EINVAL; } From e497936422d5f1e9c039dcdf9c4e7322824f84b7 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Thu, 23 Apr 2020 20:24:25 +0200 Subject: [PATCH 07/11] For now point the wifi-config-v2 to my fork --- .gitmodules | 2 +- extras/wifi-config-v2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 0e153bd..2917de2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -48,4 +48,4 @@ url = https://github.com/littlevgl/lv_examples.git [submodule "extras/wifi-config-v2"] path = extras/wifi-config-v2 - url = https://github.com/maximkulkin/esp-wifi-config.git + url = https://github.com/Rutger798/esp-wifi-config.git diff --git a/extras/wifi-config-v2 b/extras/wifi-config-v2 index 0b385c6..287b8a0 160000 --- a/extras/wifi-config-v2 +++ b/extras/wifi-config-v2 @@ -1 +1 @@ -Subproject commit 0b385c69a001db475e8152080f33c8afa0395784 +Subproject commit 287b8a0c717412a970c14c2603058bc041b11928 From 3324e61d9fcf463092346efce52676ad957bdb1a Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Sat, 25 Apr 2020 20:03:04 +0200 Subject: [PATCH 08/11] removed workaround for sntp, not needed any more becuase init is done properly --- extras/sntp/sntp_fun.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index d677c07..60a749b 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -65,7 +65,7 @@ void sntp_initialize(const struct timezone *tz) { } sntp_base = 0; // To avoid div by 0 exceptions if requesting time before SNTP config - cal = 1; + cal = sdk_system_rtc_clock_cali_proc(); tim_ref = TIMER_COUNT; sntp_sem = xSemaphoreCreateMutex(); assert(sntp_sem != NULL); @@ -96,12 +96,7 @@ int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) { // So it looks like it is not used. Also check tp is not NULL if (tzp || !tp) return EINVAL; - if (sntp_base == 0) { - printf("Time not valid yet\n"); - return EINVAL; - } - - uint64_t base = sntp_get_rtc_time(); + uint64_t base = sntp_get_rtc_time(); tp->tv_sec = base / 1000000U; tp->tv_usec = base % 1000000U; From 566b0b6ac234082dcac46699a8b823bd1006c292 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Fri, 1 May 2020 17:01:35 +0200 Subject: [PATCH 09/11] create a last sntp update ts function --- extras/sntp/sntp.h | 2 ++ extras/sntp/sntp_fun.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/extras/sntp/sntp.h b/extras/sntp/sntp.h index 4e20f0c..3863c1c 100644 --- a/extras/sntp/sntp.h +++ b/extras/sntp/sntp.h @@ -67,5 +67,7 @@ void sntp_set_update_delay(uint32_t ms); */ void sntp_update_rtc(time_t t, uint32_t us); +time_t sntp_last_update_ts(void); + #endif /* _SNTP_H_ */ diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index 60a749b..9b952d7 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -35,6 +35,8 @@ // Calibration value #define cal (RTC.SCRATCH[3]) +static time_t _sntp_update_ts = 0; + // To protect access to the above. static SemaphoreHandle_t sntp_sem = NULL; @@ -113,6 +115,7 @@ void sntp_update_rtc(time_t t, uint32_t us) { uint32_t tim = TIMER_COUNT; tim_ref = tim; sntp_base = sntp_correct; + _sntp_update_ts = t; #ifndef SKIP_DIAGNOSTICS // Assume the difference does not overflow in which case // wrapping of the RTC timer still yields a good difference. @@ -125,3 +128,11 @@ void sntp_update_rtc(time_t t, uint32_t us) { SNTP_LOGD("SNTP RTC Adjust: drift = %d usec, cal = %d", (int)(sntp_correct - sntp_current), cal); } + +time_t sntp_last_update_ts(void) { + time_t ts; + xSemaphoreTake(sntp_sem, portMAX_DELAY); + ts = _sntp_update_ts; + xSemaphoreGive(sntp_sem); + return ts; +} From 5fb09f67d6b465868e666a18b8cb2920a7c10f51 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Fri, 1 May 2020 17:36:10 +0200 Subject: [PATCH 10/11] bump wifi-config-v2 version so http socket is reusable --- extras/wifi-config-v2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/wifi-config-v2 b/extras/wifi-config-v2 index 287b8a0..d31ff82 160000 --- a/extras/wifi-config-v2 +++ b/extras/wifi-config-v2 @@ -1 +1 @@ -Subproject commit 287b8a0c717412a970c14c2603058bc041b11928 +Subproject commit d31ff82f4c355c99c8b11b7babff8b1e8c63456f From d72d11c2006feecddde25122828e41a79f55c869 Mon Sep 17 00:00:00 2001 From: Rutger Huijgen Date: Fri, 17 Jul 2020 15:48:57 +0200 Subject: [PATCH 11/11] Added thread lock around timezone update function --- extras/sntp/sntp_fun.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extras/sntp/sntp_fun.c b/extras/sntp/sntp_fun.c index 9b952d7..a704697 100644 --- a/extras/sntp/sntp_fun.c +++ b/extras/sntp/sntp_fun.c @@ -49,12 +49,14 @@ void sntp_init(void); // Sets time zone. // NOTE: Settings do not take effect until SNTP time is updated. void sntp_set_timezone(const struct timezone *tz) { + xSemaphoreTake(sntp_sem, portMAX_DELAY); if (tz) { stz = *tz; } else { stz.tz_minuteswest = 0; stz.tz_dsttime = 0; } + xSemaphoreGive(sntp_sem); } // Initialization