1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00
* 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
This commit is contained in:
kugelkopf123 2020-04-21 02:09:54 +02:00 committed by GitHub
parent ea1fdb210f
commit b02643e7fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -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);

View File

@ -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();
}