# Setting the ESP8266 internal clock

**URL:** <https://forum.arduino.cc/t/setting-the-esp8266-internal-clock/680099>\
**Category:** Programming\
**Created:** [October 26, 2020, 6:27pm UTC](https://forum.arduino.cc/t/setting-the-esp8266-internal-clock/680099 "2020-10-26T18:27:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richesonp](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@richesonp](https://forum.arduino.cc/u/richesonp)\
**Post date:** [October 26, 2020, 6:27pm UTC](https://forum.arduino.cc/t/setting-the-esp8266-internal-clock/680099/1 "2020-10-26T18:27:13Z")

</div>

I want to use the internal clock to log some data. Yes I have read that it is not that accurate. I don't need seconds accuracy. I want to save the data every 6 min. My plan is/was to get the current time from NTP. Use that to set the internal clock. than once a day update the time keeping a log of how off the internal clock is. If necessary can go to updating every 12 hours. I found an old thread that uses time.h to read the internal clock but how do you set it.

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [October 26, 2020, 6:32pm UTC](https://forum.arduino.cc/t/setting-the-esp8266-internal-clock/680099/2 "2020-10-26T18:32:57Z")

</div>

Why not just schedule a task every 360000 milliseconds?  
It could be as simple as blink without delay.

---

<div class="post-metadata">

**Author:** ![Juraj](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/juraj/32/238785_2.png) [@Juraj](https://forum.arduino.cc/u/Juraj)\
**Post date:** [October 26, 2020, 6:35pm UTC](https://forum.arduino.cc/t/setting-the-esp8266-internal-clock/680099/3 "2020-10-26T18:35:55Z")

</div>

```cpp
  configTime(TIME_ZONE, "pool.ntp.org");
  time_t now = time(nullptr);
  while (now < SECS_YR_2000) {
    delay(100);
    now = time(nullptr);
  }
  setTime(now);

```

this sets the time for the Arduino Time library (TimeLib.h). the Time library uses millis() to count the time, but you can sync it with the RTC periodically. and the RTC will sync with NTP.  
a complete sketch: [TelnetStream/TelnetStreamEsp8266Test.ino at master · JAndrassy/TelnetStream · GitHub](https://github.com/jandrassy/TelnetStream/blob/master/examples/TelnetStreamEsp8266Test/TelnetStreamEsp8266Test.ino)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:49am UTC](https://forum.arduino.cc/t/setting-the-esp8266-internal-clock/680099/4 "2021-05-06T00:49:14Z")

</div>


