Skip to content

Library to read time from Network Time Protocol (NTP) servers.

License

Notifications You must be signed in to change notification settings

wunditta/EasyNTPClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyNTPClient

Collaborizm Build Status

Arduino library to read time from Network Time Protocol (NTP) servers.

 

Features

  • Handles all heavy lifting involved with managing connections to and parsing time from an NTP server.
  • As easy as providing a UDP object to the constructor during initialization.
  • Works on Arduino and ESP8266.

 

Changes Compared to Root

  • If time update from NTP server fails, time is not set to 0 but kept as last known
  • Added functions to get info, if time update failed, and time since last update
  • Possible to set update interval (default 60 secs) with init call or separate function

 

Examples

  1. NodeMCU
    Using EasyNTPClient on a NodeMCU (ESP8266)

  2. ArduinoEspWifiShield
    Using EasyNTPClient on an Arduino UNO with an ESP-01 (ESP8266) WiFi module.
    By Claran Martis

 

Reference

Class EasyNTPClient

Initialization

  1. Possible calls
EasyNTPClient(UDP &udp);
EasyNTPClient(UDP &udp, const char* serverPool);
EasyNTPClient(UDP &udp, const char* serverPool, int offset);
EasyNTPClient(UDP &udp, const char* serverPool, int offset, unsigned int updateInterval);
  1. Parameters
    udp:             Reference to an UDP object.
    serverPool:      NTP server pool domain name. Default = "pool.ntp.org".
    offset:          Difference from UTC in seconds. Default = 0.
    updateInterval:  Update interval in seconds. Default = 60.
                     (getUnixTime will return internal unix time before the update interval is reached)
  1. Return
    EasyNTPClient object

Methods

Get time in UNIX format

unsigned long getUnixTime();

Returns:
    UTC time in UNIX time format (seconds)

Set update interval

void setInterval(unsigned int updateInterval);

Parameters:
    updateInterval: Update interval in seconds. Default = 60.

Last update successful

bool wasUpdated()

Returns:
    TRUE:  If last update was successful
    FALSE: If last update was not successful

Time since last successful update

unsigned int sinceUpdate()

Returns:
    Time in seconds since the last successful update.

Get time offset

int getTimeOffset()

Returns:
    EasyNTPClient object.

Set time offset

void setTimeOffset(int offset);

Parameters:
    offset: Difference from UTC in seconds.

About

Library to read time from Network Time Protocol (NTP) servers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%