• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32 NTP drifting

Q&A Forum › Category: ESP32 › ESP32 NTP drifting
0 Vote Up Vote Down
Pedro Ribeiro asked 2 years ago

Hello.
I’ve written code to update the ESP32 internal RTC w/ the date and time from NTP severs. There’s connection to the internet and the RTC gets updated to the correct time provided by one of the NTP servers as expected. However, after a day or so, the RTC starts to drift and it never corrects itself. It behaves as if the synch from the NTP server occurred just one time. Here’s what the code is doing:

  1. It calls configTime(0, 0, “pool.ntp.org”, “time.nist.gov”, “time.google.com”) once.
  2. It calls sntp_set_sync_interval(60000) once.
  3. Then it goes into a loop calling the getLocalTime () function;

As mentioned above, the time and date are correct initially but after about 24 hours I start noticing a drift in the time returned by getLocalTime(), i.e., it no longer matches the current time. It is as if the RTC only got updated once. Any ideas as to why this is happening?

Question Tags: NTP
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
It is normal for the ESP32 clock to drift.
Maybe you need to call the configTime() function before the getLocalTime() in the loop().
 
Let me know if this suggestion helps.
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.