Skip to content

Commit

Permalink
Improve ntp sync
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Mar 21, 2020
1 parent d6d95ce commit a2740de
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ SOFTWARE. */

#include "ntp.h"

// Check:
// https://github.com/dalmatianrex/articles/tree/master/makerpro-esp8266-ntp
// for additional functionality

void setClock() {
Ticker blinker;
Log.notice(F("Entering blocking loop to get NTP time."));
blinker.attach_ms(NTPBLINK, ntpBlinker);
configTime(0, 0, "pool.ntp.org", "time.nist.gov");
time_t nowSecs = time(nullptr);
while (nowSecs < 8 * 3600 * 2) {
configTime(GMT, 0, "pool.ntp.org", "time.nist.gov");
time_t nowSecs;
while (nowSecs < EPOCH_1_1_2019) {
#ifdef LOG_LEVEL
Serial.print(F("."));
#endif
Expand Down
37 changes: 37 additions & 0 deletions src/ntp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,41 @@ int getSecond(); // tm_sec
int getYDay(); // tm_yday
void ntpBlinker();

static const float __attribute__((unused)) GMT = 0;
static const float __attribute__((unused)) UTC = 0;
static const float __attribute__((unused)) ECT = 1.00;
static const float __attribute__((unused)) EET = 2.00;
static const float __attribute__((unused)) ART = 2.00;
static const float __attribute__((unused)) EAT = 3.00;
static const float __attribute__((unused)) MET = 3.30;
static const float __attribute__((unused)) NET = 4.00;
static const float __attribute__((unused)) PLT = 5.00;
static const float __attribute__((unused)) IST = 5.30;
static const float __attribute__((unused)) BST = 6.00;
static const float __attribute__((unused)) VST = 7.00;
static const float __attribute__((unused)) CTT = 8.00;
static const float __attribute__((unused)) JST = 9.00;
static const float __attribute__((unused)) ACT = 9.30;
static const float __attribute__((unused)) AET = 10.00;
static const float __attribute__((unused)) SST = 11.00;
static const float __attribute__((unused)) NST = 12.00;
static const float __attribute__((unused)) MIT = -11.00;
static const float __attribute__((unused)) HST = -10.00;
static const float __attribute__((unused)) AST = -9.00;
static const float __attribute__((unused)) PST = -8.00;
static const float __attribute__((unused)) PNT = -7.00;
static const float __attribute__((unused)) MST = -7.00;
static const float __attribute__((unused)) CST = -6.00;
static const float __attribute__((unused)) EST = -5.00;
static const float __attribute__((unused)) IET = -5.00;
static const float __attribute__((unused)) PRT = -4.00;
static const float __attribute__((unused)) CNT = -3.30;
static const float __attribute__((unused)) AGT = -3.00;
static const float __attribute__((unused)) BET = -3.00;
static const float __attribute__((unused)) CAT = -1.00;

static const int __attribute__((unused)) EPOCH_1_1_2019 = 1546300800; //1546300800 = 01/01/2019 @ 12:00am (UTC)
static const char __attribute__((unused)) *DAYS_OF_WEEK[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
static const char __attribute__((unused)) *DAYS_OF_WEEK_3[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

#endif // _NTP_H

0 comments on commit a2740de

Please sign in to comment.