Giter Club home page Giter Club logo

easyntpclient's Introduction

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.

 

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

1. Initialization

  1. No frills
EasyNTPClient(UDP &udp)

Parameters:
    udp: Reference to an UDP object.
Returns:
    EasyNTPClient object.
  1. Custom server pool
EasyNTPClient(UDP& udp, const char* serverPool)

Parameters:
    udp: Reference to an UDP object.
	serverPool: NTP server pool. Default = "pool.ntp.org"
Returns:
    EasyNTPClient object.
  1. Time offset
EasyNTPClient(UDP& udp, const char* serverPool, int offset);

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
Returns:
    EasyNTPClient object.

2. Methods

  1. Get time offset
int getTimeOffset()

Returns:
    EasyNTPClient object.
  1. Set time offset
void setTimeOffset(int offset);

Parameters:
    offset: Difference from UTC in seconds.
  1. Get time in UNIX format
unsigned long getUnixTime();

Returns:
    UTC time in UNIX time format (seconds)

easyntpclient's People

Contributors

aharshac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

easyntpclient's Issues

How do I know if getServerTime() succeeded?

It's entirely possible that getServerTime() could fail in which case I'd want to keep calling it until it succeeds or some timeout is reached.

But there is no way for me to know if it was successful since it's private and I only get access to it indirectly through getUnixTime() which is skewed by millis().

So ultimately, I have no way of knowing if I can rely on what getUnixTime() is telling me other than to use some "less than some smallish-value" type heuristics.

I think the library either needs a flag to indicate that the time is accurate (i.e. there was a successful NTP transaction) or getUnixTime() should return 0 until the time is accurate the way getServerTime() does.

SIM800 GSM

Hello! Please help!
Im using SIM800 GSM via TinyGSMclient library, but no examples of code how use EasyNTPClient in my case. Im search a lot but not found how tu use udp: Reference to an UDP object with TinyGSMclient.h.
Is exist many examples of ethernet or wi-fi but none of GSM.

Update setTimeOffset

I suggest adding a line to setTimeOffset() so that it changes mServerTime by the offset once the function is called.

Steps:

  1. getUnixTime()
  2. setTimeOffset(offset)
  3. getUnixTime()

Expected Behavior:

  • Return unix time + offset

Actual Behavior:

  • Return unix time

Changing:
void EasyNTPClient::setTimeOffset (int offset) { this->mOffset = offset; }
to:
void EasyNTPClient::setTimeOffset (int offset) { this->mOffset = offset; this->mServerTime = this->mServerTime + this->mOffset; }

make "mUpdateInterval" uint32_t

On some boards (e.g. ATmega like Uno) "int" is only 2 bytes and thus is capped unsigned at only roughly 65000. As mUpdateInterval holds milliseconds this more or less means that you can have 1 minute max as update interval.
I suggest to set the type of mUpdateInterval to uint32_t, which is always right.

No connection with Static IP

I'm gone mad using static IP: time is not retrieved. After a while I've discovered that if you want to use static IP, you must explicit also DNS in the wifi config:

#define USE_STATIC_IP
// data used for static IP configuration:
#ifdef USE_STATIC_IP
  IPAddress ip(192,168,1,38);		// ip address you want to assign to your board
  IPAddress gateway(192,168,1,1);	// router address
  IPAddress subnet(255,255,255,0);	// subnet mask
  IPAddress dns1(8,8,8,8); // dns 1
  IPAddress dns2(8,8,4,4);  // dns 2
#endif

// [...]

#ifdef USE_STATIC_IP
    WiFi.config(ip,gateway,subnet,dns1,dns2);
  #endif
  WiFi.begin(ssid, password);

I think It's better include this snippet in the example for ESP8266.
Thank you for the library: it's the simplest one

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.