From b02643e7fadc5c7d618613058f70835d9c16649a Mon Sep 17 00:00:00 2001 From: kugelkopf123 <45996965+kugelkopf123@users.noreply.github.com> Date: Tue, 21 Apr 2020 02:09:54 +0200 Subject: [PATCH] Tz update (#7234) * TZ update Added the possibility to set the timezone without using NTP. This is helpful to have the timezone advantages when using an external RTC. * Update time.cpp --- cores/esp8266/Arduino.h | 2 ++ cores/esp8266/time.cpp | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index a4e00ec73..edb6bdd5c 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -276,6 +276,8 @@ long secureRandom(long); long secureRandom(long, long); long map(long, long, long, long, long); +void setTZ(const char* tz); + void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); diff --git a/cores/esp8266/time.cpp b/cores/esp8266/time.cpp index 45481d91b..d6abbfc88 100644 --- a/cores/esp8266/time.cpp +++ b/cores/esp8266/time.cpp @@ -186,6 +186,14 @@ void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, c /*** end of posix replacement ***/ } +void setTZ(const char* tz){ + + char tzram[strlen_P(tz) + 1]; + memcpy_P(tzram, tz, sizeof(tzram)); + setenv("TZ", tzram, 1/*overwrite*/); + tzset(); +} + void configTime(const char* tz, const char* server1, const char* server2, const char* server3) { sntp_stop(); @@ -193,10 +201,8 @@ void configTime(const char* tz, const char* server1, const char* server2, const setServer(0, server1); setServer(1, server2); setServer(2, server3); - char tzram[strlen_P(tz) + 1]; - memcpy_P(tzram, tz, sizeof(tzram)); - setenv("TZ", tzram, 1/*overwrite*/); - tzset(); - + setTZ(tz); + sntp_init(); } +