• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    C++
  • License
    MIT License
  • Created about 4 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

High accuracy NTP library for ESP32 and ESP8266

PlatformIO

ESPNtpClient

There are many NTP client libraries around. All them have different implementations for time tracking. Indeed I developed one of them. It is called NTPClientLib and was intended to be as easy to use as possible while offering a wide range of features, including multiplatform support (ESP8266, ESP32, Arduino MKR1000, Arduino UNO with Ethernet shield). Since that I moved all my projects to ESP8266 and ESP32.

Some time ago ESP32 and ESP8266 SDKs include NTP and time tracking internal functions, including Posix compliant Time.h implementation, what gives less sense to use external libraries.

But all those libraries including Espressif SDK synchronize clock with plus minus 1 second accuracy, what is enough for most projects. But some others that require tight synchronization require additional sources of time reference, although NTP protocol is suitable to have 1 millisecond accuracy on these little boards.

This limitation comes from the way they calculate time offset. All them (at least the ones that I know) only use one of three timestamps that can be extracted from NTP packet, so they do not have round trip delay into account.

This library implementation uses time offset calculation as stated in RFC5905 NTP standard. It is not a complete implementation of NTP protocol in other aspects, although this allows getting precision very close to 1 millisecond.

Many of the methods used in my old NTPClientLib library are the same in this one. I've added some methods to get timeval times, that include microseconds information.

ESPNtpClient do not have any external dependency.


Important: This library task is only related to time synchronization and, as NTP protocol does, works using UTC time internally. All time management including local time conversion, time zones, daylight savings, etc. is done by Espressif sdk time subsystem that is based on GNU time C library. https://web.archive.org/web/20210226233334/https://kirste.userpage.fu-berlin.de/chemnet/use/info/libc/libc_17.html


Note: ESP32 and ESP8266 have their own SNTP clients into their respectives SDKs. So, unless you need additional accuracy that this library provides, it is always recommended to use ESP32 or ESP8266 SDKs.


(Attribution) Clock logo taken from https://www.visualpharm.com/free-icons/clock-595b40b75ba036ed117d92ff

Description

This is a NTP library to be able to get time from NTP server with my connected microcontrollers.

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

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 = half hour) adjusted period applies. There is a way to adjust both short and long sync period if needed.

Mostly, this is compatible with older NTPClientLib library.

This library includes an uptime log too. It counts number of seconds since sketch is started.

Every time that local time is adjusted a ntpEvent is thrown. You can attach a function to it using NTP.onNTPSyncEvent(). Called function format must be like void eventHandler(NTPSyncEvent_t event).

Library does WiFi connection tracking by itself so you can call begin after or before WiFi is connected and it takes care of WiFi reconnections. Meanwhile, if 'NTP.begin()' is called when WiFi is already connected, it takes far less to get syncronization. It takes up to 30 seconds if library is called before WiFi connection is completed, but it will only take less than 5 seconds if Wifi was connected prior to NTP.begin() call

There are two examples, one simple and minimum one to show the very basic implementation. Second one shows advanced use with event and WiFi state management.

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

NtpClient

NTP client libary for sync ESP8266 time via WiFi
C++
186
star
5

FSBrowserNG

Full autocontained (on SPIFFS) async web server on ESP8266. Written as a Library.
C++
158
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