Giter Site home page Giter Site logo

karelxkk / smallntp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gurusr/smallntp

0.0 0.0 0.0 34 KB

Original version corrected from Arduino, which is an industry standard copy of the normal NTP function which has been around for decades. This library offers async NTP, which returns the seconds from Epoch (1970 and beyond) in 2 variations for use with Watchy watch face code.

License: MIT License

C++ 100.00%

smallntp's Introduction

SmallNTP Arduino Lint

Original version corrected from Arduino, which is an industry standard copy of the normal NTP function which has been around for decades. This library offers async NTP, which returns the seconds from Epoch (1970 and beyond) in 2 variations for use with Watchy watch face code.

Begin(String NTPServer): Start a call to the NTPServer asking for the current Epoch time (UTC starting at 1970).

bool Query(): Returns true if the NTPServer's response has come in, this can be done in a loop.

End(): Stop SmallNTP from continuing in the background, do this if you get a Query() result of true or false.

time_t MakeTime(tmElements_t TM) A TimeLib.h & time.h compliant version of makeTime().

BreakTime(time_t &T, tmElements_t &TM) TimeLib.h & time.h compliant version of breakTime().

Four variables that are filled when Query() returns true:

time_t Results: has the results of the NTPServer response in time_t format, ready for use with localtime.

tmElements_t tmResults has the results from above in a format to use in either WatchyRTC or SmallRTC (GuruSR).

time_t Results1900: has the results of the NTPServer response in time_t format since 1900, ready for use with localtime.

tmElements_t tmResults1900 has the results from above in a format to use in either WatchyRTC or SmallRTC (GuruSR).

None of the four above variables survive a Deep Sleep, do not rely on them after a Deep Sleep.

How to use in your Watchy.

#include <SmallNTP.h>

...

SmallNTP sNTP; // Declare NTP object

Start the NTP process with Begin, then use Query in a loop for say 5 seconds to get the response or a timeout (your 5 seconds pass), if the Query is true, store the results from tmResults into RTC.set. For TimeZone correction I would recommend including SmallRTC and Olson2POSIX for a complete suite of functionality.

IE:

  sNTP.Begin("pool.ntp.org");
  int s = 0;
  bool b = false;
  while (!b && s < 100){
    s++;
    delay(50);
    b = sNTP.Query();
  }
  if (b) RTC.set(sNTP.tmResults);
  sNTP.End();

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.