2

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

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
2
  • 1
    Is configTime() a blocking function? Seems like it would have to be, seeing as how the Arduino is not a multi-tasking system. Commented 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 but configTime is a C function from SDK, so the function only activates SNTP Commented Jul 23, 2020 at 13:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.