diff --git a/timeRequest.ino b/timeRequest.ino index 39c317b..1cc52a3 100644 --- a/timeRequest.ino +++ b/timeRequest.ino @@ -20,7 +20,7 @@ #endif #define MY_RF24_CHANNEL 83 #define MY_BAUD_RATE 57600 -//#define MY_DEBUG +#define MY_DEBUG #define SKETCH_NAME "timeRequest" #define SKETCH_VERSION "20171203_01" @@ -43,7 +43,7 @@ void receiveTime(unsigned long ts) { - const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2017 + const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 #ifdef MY_DEBUG Serial.print('['); @@ -107,7 +107,15 @@ } // printTime -void setup() +time_t requestSync() +{ + requestTime(); + delay(500); // wait for tiem receiving + return 0; +} // requestSync + + +void before() { Serial.begin(MY_BAUD_RATE); Serial.println(""); @@ -115,9 +123,17 @@ Serial.print(F("Version: ")); Serial.println(F(SKETCH_VERSION)); Serial.flush(); +} - // request time at first - requestTime(); + +void setup() +{ + Serial.print('['); + Serial.print(millis() / 1000); + Serial.println(F("]: setup")); + Serial.flush(); + + setSyncProvider(requestSync); } // setup @@ -130,13 +146,14 @@ { lastRequest = currentTime; requestTime(); + printTime(); } #else - static unsigned int lastHour = 0; + static unsigned char lastHour = 0; // request time every our - if (hour() != lastHour) + if (hour() != lastHour || year() == 1970) { - requestTime(); + requestSync(); lastHour = hour(); }