Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: import IANA timezone definitions, expose SNTP API #6373

Merged
merged 38 commits into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b8448e7
time: import IANA timezone definitions
d-a-v Aug 1, 2019
802d228
fix former configTime non-matching signature
d-a-v Aug 1, 2019
8ee720b
+include
d-a-v Aug 1, 2019
452706c
Merge branch 'master' into ntpexamplev2
d-a-v Sep 2, 2019
f0ebbe6
example: add scheduled function in callback
d-a-v Sep 2, 2019
d023a0c
Merge branch 'master' into ntpexamplev2
d-a-v Sep 6, 2019
60e565e
crlf fix
d-a-v Sep 6, 2019
b825a36
+missing license for napt
d-a-v Sep 6, 2019
d141e61
SNTP: expose configuration helpers
d-a-v Sep 6, 2019
b9a8eaa
update submodule
d-a-v Sep 6, 2019
c665bb2
update precompiled libraries
d-a-v Sep 6, 2019
e1ec8cc
optional: change SNTP startup delay
d-a-v Sep 6, 2019
c2c48fc
makes SNTP_UPDATE_DELAY a weak function
d-a-v Sep 8, 2019
ac5948f
on the proper use of polledTimeout api... thanks @mcspr :]
d-a-v Sep 9, 2019
857f67b
improve update script (per review)
d-a-v Sep 9, 2019
b96ce9a
Merge branch 'master' into ntpexamplev2
d-a-v Sep 9, 2019
ddca580
update lwIP submodule
d-a-v Sep 9, 2019
a109804
update submodule
d-a-v Sep 9, 2019
d10da64
Merge branch 'ntpexamplev2' of github.com:d-a-v/Arduino into ntpexamp…
d-a-v Sep 9, 2019
fb38186
hide harmless shell message
d-a-v Sep 10, 2019
25d5b32
Merge branch 'master' into ntpexamplev2
d-a-v Sep 11, 2019
a82ddcd
Merge branch 'master' into ntpexamplev2
earlephilhower Sep 13, 2019
233583a
Merge branch 'master' into ntpexamplev2
d-a-v Sep 21, 2019
91e3fef
update the release process by asking first to update TZ.h
d-a-v Sep 21, 2019
c2ad512
Merge branch 'master' into ntpexamplev2
d-a-v Sep 23, 2019
1b2fe6d
minor update in release documentation
d-a-v Sep 24, 2019
293760b
update in release documentation
d-a-v Sep 24, 2019
52c6012
update in release documentation
d-a-v Sep 24, 2019
2914603
clarify release documentation
d-a-v Sep 24, 2019
b634672
fix release documentation - sorry for the noise :(
d-a-v Sep 24, 2019
76b6a97
Merge branch 'master' into ntpexamplev2
earlephilhower Sep 26, 2019
e070886
Merge branch 'master' into ntpexamplev2
d-a-v Sep 28, 2019
714c294
fixes per review
d-a-v Sep 29, 2019
b49cdfc
example style
d-a-v Sep 29, 2019
f884a48
Merge branch 'master' into ntpexamplev2
d-a-v Sep 29, 2019
27b0af3
useless variable in example
d-a-v Sep 29, 2019
eaef5e1
update lwip2 submodule reference, to include espressif missing declar…
d-a-v Sep 29, 2019
58c61c2
Merge branch 'ntpexamplev2' of github.com:d-a-v/Arduino into ntpexamp…
d-a-v Sep 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ long secureRandom(long);
long secureRandom(long, long);
long map(long, long, long, long, long);

extern "C" void configTime(long timezone, int daylightOffset_sec,
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
void configTime(int timezone, int daylightOffset_sec, const char* server1,
devyte marked this conversation as resolved.
Show resolved Hide resolved
const char* server2 = nullptr, const char* server3 = nullptr);

#endif
void configTime(const char* tz, const char* server1,
const char* server2 = nullptr, const char* server3 = nullptr);

#endif // __cplusplus

#include "pins_arduino.h"

Expand Down
475 changes: 475 additions & 0 deletions cores/esp8266/TZ.h

Large diffs are not rendered by default.

49 changes: 33 additions & 16 deletions cores/esp8266/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*/

#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/reent.h>
Expand Down Expand Up @@ -55,25 +56,12 @@ static void setServer(int id, const char* name_or_ip)
{
if (name_or_ip)
{
//TODO: check whether server is given by name or IP
// per current configuration,
// lwIP can receive an IP address or a fqdn
sntp_setservername(id, (char*) name_or_ip);
}
}


void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
{
sntp_stop();

setServer(0, server1);
setServer(1, server2);
setServer(2, server3);

sntp_set_timezone_in_seconds(timezone_sec);
sntp_set_daylight(daylightOffset_sec);
sntp_init();
}

int clock_gettime(clockid_t unused, struct timespec *tp)
{
(void) unused;
Expand Down Expand Up @@ -108,4 +96,33 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
return 0;
}

};
}; // extern "C"

void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
{
sntp_stop();

setServer(0, server1);
setServer(1, server2);
setServer(2, server3);

sntp_set_timezone_in_seconds(timezone_sec);
sntp_set_daylight(daylightOffset_sec);
sntp_init();
}

void configTime(const char* tz, const char* server1, const char* server2, const char* server3)
{
sntp_stop();

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

sntp_init();
}
Loading