enable auto update datetime #25

pull/1/head
Thomas Ballmann 4 years ago
parent 754ab33514
commit 228e6c7ad6

@ -10,6 +10,8 @@ const char *ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600; const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600; const int daylightOffset_sec = 3600;
unsigned long lastUpdate = 0;
int getNumberOfDays(int month, int year) int getNumberOfDays(int month, int year)
{ {
// leap year condition, if month is 2 // leap year condition, if month is 2
@ -29,13 +31,12 @@ int getNumberOfDays(int month, int year)
bool updateDateTime() bool updateDateTime()
{ {
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); //configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
if (!getLocalTime(&now)) if (!getLocalTime(&now))
{ {
Serial.println("Failed to obtain time"); Serial.println("Failed to obtain time");
return false; return false;
} }
Serial.println(&now, "%A, %B %d %Y %H:%M:%S");
// //
now.days_in_month = getNumberOfDays(now.tm_mon + 1, now.tm_year); now.days_in_month = getNumberOfDays(now.tm_mon + 1, now.tm_year);
@ -53,15 +54,23 @@ bool updateDateTime()
void setupDateTime() void setupDateTime()
{ {
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
if (!updateDateTime()) if (!updateDateTime())
{ {
// re-try // re-try
updateDateTime(); updateDateTime();
} }
Serial.println(&now, "%A, %B %d %Y %H:%M:%S");
lastUpdate = millis();
} }
void loopDateTime() void loopDateTime()
{ {
// TODO update... if ((millis() - lastUpdate) >= 1000)
//setupDateTime(); {
lastUpdate = millis();
updateDateTime();
}
} }
Loading…
Cancel
Save