Skip to content

Commit ffe5476

Browse files
d-a-vdevyte
authored andcommitted
time: import IANA timezone definitions, expose SNTP API (#6373)
* time: import IANA timezone definitions - `configTime("timezone", "ntp servers...")` added - timezone definitions by country/cities (TZ.h) - script to update timezone definitions - updated example * fix former configTime non-matching signature * +include * example: add scheduled function in callback * crlf fix * +missing license for napt * SNTP: expose configuration helpers * update submodule * update precompiled libraries * optional: change SNTP startup delay * makes SNTP_UPDATE_DELAY a weak function update example fix for lwip1.4 * on the proper use of polledTimeout api... thanks @mcspr :] * improve update script (per review) * update lwIP submodule * update submodule * hide harmless shell message * update the release process by asking first to update TZ.h [ci skip] * minor update in release documentation * update in release documentation * update in release documentation * clarify release documentation * fix release documentation - sorry for the noise :( * fixes per review * example style * useless variable in example * update lwip2 submodule reference, to include espressif missing declaration fixes
1 parent 4489e23 commit ffe5476

18 files changed

+966
-256
lines changed

cores/esp8266/Arduino.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ long secureRandom(long);
275275
long secureRandom(long, long);
276276
long map(long, long, long, long, long);
277277

278-
extern "C" void configTime(long timezone, int daylightOffset_sec,
279-
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
278+
void configTime(int timezone, int daylightOffset_sec, const char* server1,
279+
const char* server2 = nullptr, const char* server3 = nullptr);
280280

281-
#endif
281+
void configTime(const char* tz, const char* server1,
282+
const char* server2 = nullptr, const char* server3 = nullptr);
283+
284+
#endif // __cplusplus
282285

283286
#include "pins_arduino.h"
284287

cores/esp8266/TZ.h

+475
Large diffs are not rendered by default.

cores/esp8266/time.cpp

+33-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818

19+
#include <stdlib.h>
1920
#include <time.h>
2021
#include <sys/time.h>
2122
#include <sys/reent.h>
@@ -55,25 +56,12 @@ static void setServer(int id, const char* name_or_ip)
5556
{
5657
if (name_or_ip)
5758
{
58-
//TODO: check whether server is given by name or IP
59+
// per current configuration,
60+
// lwIP can receive an IP address or a fqdn
5961
sntp_setservername(id, (char*) name_or_ip);
6062
}
6163
}
6264

63-
64-
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
65-
{
66-
sntp_stop();
67-
68-
setServer(0, server1);
69-
setServer(1, server2);
70-
setServer(2, server3);
71-
72-
sntp_set_timezone_in_seconds(timezone_sec);
73-
sntp_set_daylight(daylightOffset_sec);
74-
sntp_init();
75-
}
76-
7765
int clock_gettime(clockid_t unused, struct timespec *tp)
7866
{
7967
(void) unused;
@@ -108,4 +96,33 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
10896
return 0;
10997
}
11098

111-
};
99+
}; // extern "C"
100+
101+
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
102+
{
103+
sntp_stop();
104+
105+
setServer(0, server1);
106+
setServer(1, server2);
107+
setServer(2, server3);
108+
109+
sntp_set_timezone_in_seconds(timezone_sec);
110+
sntp_set_daylight(daylightOffset_sec);
111+
sntp_init();
112+
}
113+
114+
void configTime(const char* tz, const char* server1, const char* server2, const char* server3)
115+
{
116+
sntp_stop();
117+
118+
setServer(0, server1);
119+
setServer(1, server2);
120+
setServer(2, server3);
121+
122+
char tzram[strlen_P(tz) + 1];
123+
memcpy_P(tzram, tz, sizeof(tzram));
124+
setenv("TZ", tzram, 1/*overwrite*/);
125+
tzset();
126+
127+
sntp_init();
128+
}

0 commit comments

Comments
 (0)