diff --git a/WLAN_Thermometer.ino b/WLAN_Thermometer.ino index 42ffdba..bb8133c 100644 --- a/WLAN_Thermometer.ino +++ b/WLAN_Thermometer.ino @@ -118,16 +118,19 @@ void setup() lcd.setCursor(0, 3); lcd.print("Getting time..."); DateTime.setTimeZone(1); - DateTime.begin(NTP_TIMEOUT); - while (!DateTime.isTimeValid()) - { + DateTime.begin(); + /* while (!DateTime.isTimeValid()) + { DEBUG_MSG("Failed to get time from server.\n"); DateTime.forceUpdate(); + }*/ + if (DateTime.isTimeValid()) + { + if (is_wintertime(DateTime.getTime()) == false) + add_summertime = 1; + else + add_summertime = 0; } - if (is_wintertime(DateTime.getTime()) == false) - add_summertime = 1; - else - add_summertime = 0; // create a degree sign lcd.createChar(0, (uint8_t*)degree_sign); @@ -155,8 +158,21 @@ void setup() void loop() { + static uint32_t next_time_check; + sched.scheduler(); + if (!DateTime.isTimeValid() && millis() - 10000 > next_time_check) + { + next_time_check = millis(); + DateTime.setTimeZone(1); + DateTime.forceUpdate(); + if (is_wintertime(DateTime.getTime()) == false) + add_summertime = 1; + else + add_summertime = 0; + } + WiFiClient client = server.available(); // Listen for incoming clients if (client) { // If a new client connects, @@ -248,24 +264,27 @@ void loop() } client.println("\n"); - DateTimeParts p = DateTime.getParts(); - char dt[21]; - - if (is_wintertime(DateTime.getTime()) == false) - add_summertime = 1; - else - add_summertime = 0; - - client.println("
\n"); - client.print("

"); - - sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours() + add_summertime, p.getMinutes(), p.getSeconds()); - client.print(dt); - if (add_summertime > 0) - client.print(" Sommerzeit\n"); - else - client.print(" Winterzeit\n"); - client.println("

\n"); + if (DateTime.isTimeValid()) + { + DateTimeParts p = DateTime.getParts(); + char dt[21]; + + if (is_wintertime(DateTime.getTime()) == false) + add_summertime = 1; + else + add_summertime = 0; + + client.println("
\n"); + client.print("

"); + + sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours() + add_summertime, p.getMinutes(), p.getSeconds()); + client.print(dt); + if (add_summertime > 0) + client.print(" Sommerzeit\n"); + else + client.print(" Winterzeit\n"); + client.println("

\n"); + } client.println("\n"); client.println("\n"); @@ -327,27 +346,32 @@ void check_reset_ap_data(void) void show_time(void) { - DateTimeParts p = DateTime.getParts(); char dt[21]; - if (p.getHours() == 0 && p.getMinutes() == 0 && p.getSeconds() == 0) - DateTime.forceUpdate(); - - if ((p.getHours() == 2 || p.getHours() == 3) && p.getMinutes() == 0 && p.getSeconds() == 0) + if (DateTime.isTimeValid()) { - if (is_wintertime(DateTime.getTime()) == false) - add_summertime = 1; + DateTimeParts p = DateTime.getParts(); + + if (p.getHours() == 0 && p.getMinutes() == 0 && p.getSeconds() == 0) + DateTime.forceUpdate(); + + if ((p.getHours() == 2 || p.getHours() == 3) && p.getMinutes() == 0 && p.getSeconds() == 0) + { + if (is_wintertime(DateTime.getTime()) == false) + add_summertime = 1; + else + add_summertime = 0; + } + + sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours() + add_summertime, p.getMinutes(), p.getSeconds()); + DEBUG_MSG("%s", dt); + if (add_summertime > 0) + DEBUG_MSG(" Summertime\n"); else - add_summertime = 0; + DEBUG_MSG(" Wintertime\n"); } - - sprintf(dt, "%02d.%02d.%4d %02d:%02d:%02d", p.getMonthDay(), p.getMonth() + 1, p.getYear(), p.getHours() + add_summertime, p.getMinutes(), p.getSeconds()); - DEBUG_MSG("%s", dt); - if (add_summertime > 0) - DEBUG_MSG(" Summertime\n"); else - DEBUG_MSG(" Wintertime\n"); - + sprintf(dt, "--:--:---- --:--:--"); lcd.setCursor(0, 0); lcd.print(dt);