I am working on ESP32 And want to set RTC from the NTP server. How can I get epoch value I have done this thing on CC3200 launchpad and used an NTP server library to obtain epoch value.
asked Jul 23, 2020 at 7:28
1 Answer 1
this snippet from setup() sets on esp32 the NTP for internal RTC and uses epoch seconds to set time to TimeLib library.
configTime(gmtOffset_sec, daylightOffset_sec, "pool.ntp.org");
time_t now = time(nullptr);
while (now < SECS_YR_2000) {
delay(100);
now = time(nullptr);
}
setTime(now);
The ESP32 examples library in IDE examples folder has example SimpleTime.
answered Jul 23, 2020 at 8:12
-
1Is
configTime()
a blocking function? Seems like it would have to be, seeing as how the Arduino is not a multi-tasking system.Duncan C– Duncan C2020年07月23日 12:07:41 +00:00Commented Jul 23, 2020 at 12:07 -
@DuncanC, it is not blocking as you can see on the following
while
cycle. esp32 core is on esp32 RTOS SDK. arduino is one thread butconfigTime
is a C function from SDK, so the function only activates SNTP2020年07月23日 13:00:59 +00:00Commented Jul 23, 2020 at 13:00