Giter Club home page Giter Club logo

ntpclient's Introduction

*** Archived ***

Now that version 2.4.0 (and above) of the ESP8266 core for Arduino library provides proper support for timezones and DST, this library has served it's purpose and has been archived.

This library becoming obsolete is a good thing: developers write their own libraries, API's, etc simply because features in existing projects are lacking or bugs are present. These efforts are an important part of OSS: helping each other to make software better.

If you're using version 2.4.0 (or above) of the ESP8266 core for Arduino library, and want to know how to implement SNTP functions in your project, checkout the NTP-TZ-DST example.

Please fork it, use it as an archive, a reference or as an example to learn developing ESP8266/Arduino sketches/libraries :)

NTPClient

A simple and small NTP Client library to have date and time on your ESP8266 device synchronized periodically, supporting timezones.

For Internet connected devices like the ESP8266, Arduino, etc. having a correct time and date for your project can be essential. For these devices plenty of good NTP libraries are available, however most of these contain too many features. In addition, supporting timezones (i.e. UTC offsets) are often implemented poorly.

This NTPClient library makes use of the internal Espressif SDK routines for the built in SNTP API, allowing this client to be small and simple. Unfortunately the timezone implementation of the SNTP API is limited in that only UTC offsets between -11 and 13 hour offsets can be used. Currently UTC offsets range from -12 to 14 hours including some timezones that are not a full hour (e.g. 05:30, 05:45). This NTPClient library overcomes that and fully supports all known timezones.

Using the NTPClient library is very straightforward and simple. Include this NTPClient library in your project and start the synchronization by calling the NTP.init function. You can use it without any parameters (defaults will be used) or adjust to your liking. It is recommended to use a NTP server closer to your location and the appropriate timezone (i.e. UTC offset). Please refer to the header file for the full list of UTC offsets.

By default a polling interval of 30 minutes is used for synchronizing with the NTP server. You may adjust this by using the NTP.setPollingInterval(interval) function, where interval is the desired interval in seconds.

To keep the NTPClient library small, no functions other than NTP.getTimeDate(time_t _time) are implemented that output time and date in a human readable format. The NTP.getTimeDate(time_t _time) will render the given time in ISO8601 format.

For more advanced use, a callback function may be used to handle some events emitted by the NTPClient library. The following events are currently implemented:

  • NTP_EVENT_INIT: Issued upon start of the synchronization.
  • NTP_EVENT_STOP: Issued when the synchronization is stopped.
  • NTP_EVENT_NO_RESPONSE: Issued when no response is received from the NTP server.
  • NTP_EVENT_SYNCHRONIZED: Issued when time has been successfully synchronized.

A full working example is included in the examples folder.

Making this library was heavily inspired by the wonderful NTPClient Library of Germán Martín.

Disclaimer

The SNTP protocol is a simple implementation of the NTP protocol, therefore disregarding time drift values and using simplified ways of system clock adjustment methods. Hence, complete accuracy and reliability can not be guaranteed however time synchronization in the range of 1 to 2 seconds is achievable.

This NTPClient library is designed for the ESP8266 device only. Other MCU like Arduino, etc. are not supported.

DST is currently not supported. The use of DST varies by region or country and can also change over time.

Requirements/Dependencies

You will need version 2.3.0 of the ESP8266 core for Arduino library. Any newer versions are known to work however with some issues.

This library makes use of the Time library. You need to add it to use this NTPClient.

Contributing

Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on Github :)

License

The NTPClient library is open-sourced software licensed under the MIT license. For the full copyright and license information, please see the LICENSE file that was distributed with this source code.

ntpclient's People

Contributors

stelgenhof 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ntpclient's Issues

Not possible to install the library

Dear Sir,
I have Arduino IDE 1.6.9 installed at Windows 10 laptop, and I tried to install your library both with the manual way ( download,, extract / rename the unzipped directory as NTPClient and transferred to the appropriate library directory ) and the Arduino "Add .ZIP library ..." way, both without success unfortunately... In the "Add .ZIP library ..." I got the following error: "Specified folder/zip file does not contain a valid library"

and in the manual way invalid library as well.

Please guide me what is wrong...

Thanks and Best Regards,
Mike Kranidis

P.S. Sorry, I forgot to say a BIG THANKS for your fine as I can understand library (sorry not possible to run it yet...!)

First NTP sync is wrong

Hej

I am testing your code on a SonOff Th10 but I have a slight problem the first sync gives me the wrong time.

Serial print follows

`MDNS responder started
HTTP server started
....Got IP: 192.168.1.21

Got NTP time: 1970-01-01T00:00:08 last sync 1970-01-01T09:00:02
Got NTP time: 1970-01-01T09:01:02 last sync 2018-01-08T14:57:02
Got NTP time: 2018-01-08T14:58:03 last sync 2018-01-08T14:58:04
Got NTP time: 2018-01-08T14:59:05 last sync 2018-01-08T14:59:05
`

I have changed to print out the current time also.

`
case NTP_EVENT_SYNCHRONIZED:

Serial.printf("Got NTP time: %s last sync %s\n", NTP.getTimeDate(now()), NTP.getTimeDate(NTP.getLastSync()));

break;`

Any ideas whats going on. The NTP server works when using regular ntpdate so thats not the issue.
I was thinking maybe I could force the update in setup but gettime is private so that is not an option at this stage.

cheers

How to use local IP

Hi,

i have my own timeserver in my LAN.
How can i use the local IP instead of a domain?

NTPCLient.ino doesn't free the char buffer allocated inside NTPClient::getTimeDate

The example program NTPClient repeatedly calls const char *NTPClient::getTimeDate(time_t tm).
This method allocates a char buffer and returns a pointer to this buffer to the caller.
NTPClient.ino should free these pointers but doesn't.
The (demonstrated) result is that 24 bytes of the heap is lost on each call of getTimeDate () and the program finally crashes.

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.