diff --git a/timeRequest.ino b/timeRequest.ino index 7658622..9a6905a 100644 --- a/timeRequest.ino +++ b/timeRequest.ino @@ -2,7 +2,10 @@ * @file timeRequest.ino * @author Pascal Gollor * @date 2017-12-03 - * @breif + * + * use libraries: + * - MySensors (https://github.com/mysensors/MySensors) + * - Time (https://github.com/PaulStoffregen/Time) */ @@ -26,6 +29,7 @@ // ----- includes ----- #include #include +#include @@ -37,12 +41,39 @@ } // presentation +void printDigits(int digits){ + // utility function for digital clock display: prints preceding colon and leading 0 + Serial.print(":"); + if(digits < 10) + Serial.print('0'); + Serial.print(digits); +} // printDigits + + void receiveTime(unsigned long ts) { + const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2017 + Serial.print('['); Serial.print(millis() / 1000); Serial.print(F("]: ts: ")); Serial.println(ts); + + if (ts > DEFAULT_TIME) + { + setTime(ts); + + Serial.print(hour()); + printDigits(minute()); + printDigits(second()); + Serial.print(" "); + Serial.print(day()); + Serial.print(" "); + Serial.print(month()); + Serial.print(" "); + Serial.print(year()); + Serial.println(); + } } // receiveTime