More checking if time values are ok.

master
Holger Wirtz 4 years ago
parent e4e8ca5df5
commit 9a3f2c151d
  1. 104
      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("</h2>\n");
DateTimeParts p = DateTime.getParts();
char dt[21];
if (is_wintertime(DateTime.getTime()) == false)
add_summertime = 1;
else
add_summertime = 0;
client.println("<hr>\n");
client.print("<h4 style=\"color:black;\">");
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("</h2>\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("<hr>\n");
client.print("<h4 style=\"color:black;\">");
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("</h2>\n");
}
client.println("</center>\n");
client.println("</body>\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);

Loading…
Cancel
Save