mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-02 14:22:55 +03:00
configTime(tzsec,dstsec,): fix UTC/local management (#6993)
* configTime(tzsec,dstsec,): fix UTC/local management This PR also remove dead code since probably newlib updates The NTP-TZ-DST example is also updated * restore sntp_set_timezone_in_seconds() fixes #6678 * +configTzTime()
This commit is contained in:
@ -134,13 +134,14 @@ void showTime() {
|
||||
Serial.println((uint32_t)now);
|
||||
|
||||
// timezone and demo in the future
|
||||
Serial.printf("timezone: %s\n", MYTZ);
|
||||
Serial.printf("timezone: %s\n", getenv("TZ"));
|
||||
|
||||
// human readable
|
||||
Serial.print("ctime: ");
|
||||
Serial.print(ctime(&now));
|
||||
|
||||
#if LWIP_VERSION_MAJOR > 1
|
||||
|
||||
// LwIP v2 is able to list more details about the currently configured SNTP servers
|
||||
for (int i = 0; i < SNTP_MAX_SERVERS; i++) {
|
||||
IPAddress sntp = *sntp_getserver(i);
|
||||
@ -203,8 +204,7 @@ void setup() {
|
||||
// it will be used until NTP server will send us real current time
|
||||
time_t rtc = RTC_UTC_TEST;
|
||||
timeval tv = { rtc, 0 };
|
||||
timezone tz = { 0, 0 };
|
||||
settimeofday(&tv, &tz);
|
||||
settimeofday(&tv, nullptr);
|
||||
|
||||
// install callback - called when settimeofday is called (by SNTP or us)
|
||||
// once enabled (by DHCP), SNTP is updated every hour
|
||||
@ -212,8 +212,18 @@ void setup() {
|
||||
|
||||
// NTP servers may be overriden by your DHCP server for a more local one
|
||||
// (see below)
|
||||
|
||||
// ----> Here is the ONLY ONE LINE needed in your sketch
|
||||
|
||||
configTime(MYTZ, "pool.ntp.org");
|
||||
|
||||
// Here is the ONLY ONE LINE needed in your sketch <----
|
||||
// pick a value from TZ.h (search for this file in your filesystem) for MYTZ
|
||||
|
||||
// former configTime is still valid, here is the call for 7 hours to the west
|
||||
// with an enabled 30mn DST
|
||||
//configTime(7 * 3600, 3600 / 2, "pool.ntp.org");
|
||||
|
||||
// OPTIONAL: disable obtaining SNTP servers from DHCP
|
||||
//sntp_servermode_dhcp(0); // 0: disable obtaining SNTP servers from DHCP (enabled by default)
|
||||
|
||||
|
Reference in New Issue
Block a user