• Stars
    star
    186
  • Rank 207,316 (Top 5 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created almost 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NTP client libary for sync ESP8266 time via WiFi

Notice

With new improvements in sdk both for esp32 and esp8266, this library has become less usefull. Using internal functions of IDF or NonOS (esp8266) have several advantages and it is mandatory for certain scenarios, like using HTTPS with certificate check.

For that reason this library will be deprecated. I will keep the repository opened for archive reasons, but I will not make any big development on it.

I'll copy the recommended NTP initialisation code for both ESP8266 and ESP32 using Arduino. It is easy and convenient.

Arduino MKR1000 users, if any, can keep using it.


New library announcement

(23/nov/2020) - Due to a current project I needed having NTP synchronization with millisecond accuracy. It is not currently implemented in any NTP client library or internal Espressif SDK. So, I've started a new library that focuses on high accuracy sync. It only supports ESP8266 and ESP32.

You can find it on GitHub repository https://github.com/gmag11/ESPNtpClient

It relies in internal Posix Time implementation so it is integrated on SDK time calculation. This means that it can be used with TLS mechanism to check certificates validity.


NtpClientLib

Introduction

There are some NTP client examples around. You can see some examples, like this.

In a device like ESP8266 or any Internet connected Arduino having NTP synchronization is well convenient. Using that example you can add NTP client to your projects but I was looking for a quicker way to add it, using something like NTPClient class.

So I decided to do my own NTP client library to sync ESP8266 time via WiFi using Arduino IDE. It can also be used on any ethernet or WiFi connected Arduino, although as I do not have any WiFi enabled Arduino code is not tested. Testers are welcome.

This library support both Arduino MKR1000, ESP8266 and ESP32.

Description

This is a NTP library to be able to get time from NTP server with my connected microcontrollers. Support for regular Arduino with ethernet shield, ESP8266, ESP32 and Arduino MKR1000 is available. Please test it and inform via GitHub.

Using the library is fairly easy. A NTP singleton object is created inside library. You may use default values by using NTP.begin() without parameters. After that, synchronization is done regularly without user intervention. Some parameters can be adjusted: server, sync frequency, time offset.

You don't need anything more. Time update is managed inside library so, after NTP.begin() no more calls to library are needed.

Update frequency is higher (every 15 seconds as default) until 1st successful sync is achieved. Since then, your own (or default 1800 seconds) adjusted period applies. There is a way to adjust both short and long sync period if needed.

In current version source code is the same for all platforms. There has been some interface changes during last update. Although I've tried to keep backwards compatibility you may find some discrepancies. Let me know so that I can correct it.

This library includes an uptime log too. It counts number of seconds since sketch is started. It can be checked calling NTP.getUptime() or NTP.getUptimeString() for a human readable string.

Every time that local time is adjusted a ntpEvent is thrown. You can attach a function to it using NTP.onNTPSyncEvent(). Indeed, this event is thrown just before time is sent to [Time] Library. Because of that, you should try not to make time consuming tasks inside event handler. Although it is taken into account inside library, it would add some offset to calculated time. My recommendation is to use a flag and process it inside loop()function.

Called function format must be like void eventHandler(NTPSyncEvent_t event).

ESP8266 example uses a simple function to turn a flag on, so actual event handling code is run inside main loop.

Examples

Please check examples folder into repository source code.

Performance

Don't expect atomic-clock-like precision. This library does not take network delay into account neither uses all NTP mechanisms available to improve accuracy. It is in the range of 1 to 2 seconds. Enough for most projects.

I have the plan to add full network delay compensation. Due to limited Time Library precision of 1 second, it probably will not affect overall accuracy.

Dependencies

This library makes use of Time library. You need to add it to use NTPClientLib

More Repositories

1

painlessMesh

ESP8266 based mesh. This is a mirror copy of https://gitlab.com/painlessMesh/painlessMesh PLEASE ADD COMMENTS, ISSUES and PULL REQUESTS ON GITLAB so that all information is centralized.
C++
519
star
2

EnigmaIOT

Secure sensor and gateway platform based on ESP8266 and ESP32
C++
237
star
3

WifiLocation

Google GeoLocation API wrapper for Arduino MKR1000, ESP8266 and ESP32
C++
211
star
4

FSBrowserNG

Full autocontained (on SPIFFS) async web server on ESP8266. Written as a Library.
C++
158
star
5

ESPNtpClient

High accuracy NTP library for ESP32 and ESP8266
C++
118
star
6

QuickESPNow

Wrapper for easy use of ESP-NOW on ESP32 and ESP8266
C++
90
star
7

MetaTrader5-Docker-Image

Docker image that runs Metatrader 5 with VNC web server
Shell
88
star
8

FSBrowser

Full autocontained (on SPIFFS) web server on ESP8266
HTML
31
star
9

FailSafeMode

Fail Safe mode implementation for ESP8266 and ESP32 to avoid OTA update problems
C++
16
star
10

Curso-ESP32

C++
8
star
11

BTClassicSPP

Bluetooth Classic serial library to work as master of slave
C++
8
star
12

FirmataMaster

Firmata client (master) library for ESP8266 (or any other Arduino compatible board)
C++
7
star
13

QuickDebug

C++
4
star
14

CayenneLPPdec

CayenneLPP data decoder for Arduino platform
C++
4
star
15

OpenLedRace-Wireless-Remote

Make your OpenLedRace game wireless with EnigmaIOT
C++
4
star
16

QuickLoRaWAN

LMIC wrapper library to create LoRaWAN OTAA nodes with a few lines of code with ESP32 and ESP8266
C++
3
star
17

MQTT-MQL5-Library

MQTT client library for MetaTrader 5
MQL5
3
star
18

rne.es-program-guide-XMLTV-generator

Small Python program I've made to learn web scrapping. It takes program schedules from www.rne.es and export it to a XMLTV file
Python
2
star
19

WeatherDisplay

Weather information display without sensors using ESP8266 and OLED display
Arduino
2
star
20

CurrentCostLib

Library for getting XML feed from CurrentCost devices via softserial connections. For Arduino IDE
C++
1
star
21

CurrentCost

CurrentCost WiFi Monitor
C++
1
star
22

CoulombMeter

Power meter for low power devices using LTC4150
1
star