- Sun May 10, 2020 3:11 am
#87010
I can't tell for the pure sdk functions as I never used sdk itself.
But what I see from the sdk functions in the earlier core versions regarding ntp and "time" it is unusable as it depends on the user setting the exact timezone difference in seconds and manually taking care of summertime. Additionally there are none of the standard time functions therefor the need for 3rd party time lib, confusing newbies as they find lots of incompatible timelibs on google (giving trouble in compiling and running).
in recent cores ntp-client and timelib functionality is included (partly in lwIP, newlib).
Example how to use:
https://github.com/esp8266/Arduino/blob ... TZ-DST.inoit is an example demonstrating all of the features, so it might be a little confusing.
Code: Select all#include <coredecls.h> // settimeofday_cb()
#include <Schedule.h>
#include <PolledTimeout.h>
#include <sntp.h> // sntp_servermode_dhcp()
extern "C" int clock_gettime(clockid_t unused, struct timespec *tp);
are only necessary for demonstration of the "features"
is not for including a "new time lib" but to get the variable type defines
For the basic "get time" it is only few lines to initialize and use.
Code: Select all#define NTP0 "0.pool.ntp.org"
#define NTP1 "1.pool.ntp.org"
#define TZ "CET-1CEST,M3.5.0,M10.5.0/3"
void setup() {
time_t tnow;
struct tm *ti;
setenv("TZ", TZ, 0);
tzset();
configTime(0, 0, NTP0, NTP1);
//start WiFi here
wifi.begin()
// wait until we get ntp time
while (t < 300000) {
t = time(nullptr);
delay(10);
}
tnow = time(nullptr);
Serial.println(ctime(&tnow));
ti = localtime(&tnow);
Serial.println(asctime(ti));
}
void loop {
}