More checking if time values are ok.

master
Holger Wirtz 4 years ago
parent e4e8ca5df5
commit 9a3f2c151d
  1. 34
      WLAN_Thermometer.ino

@ -118,16 +118,19 @@ void setup()
lcd.setCursor(0, 3); lcd.setCursor(0, 3);
lcd.print("Getting time..."); lcd.print("Getting time...");
DateTime.setTimeZone(1); DateTime.setTimeZone(1);
DateTime.begin(NTP_TIMEOUT); DateTime.begin();
while (!DateTime.isTimeValid()) /* while (!DateTime.isTimeValid())
{ {
DEBUG_MSG("Failed to get time from server.\n"); DEBUG_MSG("Failed to get time from server.\n");
DateTime.forceUpdate(); DateTime.forceUpdate();
} }*/
if (DateTime.isTimeValid())
{
if (is_wintertime(DateTime.getTime()) == false) if (is_wintertime(DateTime.getTime()) == false)
add_summertime = 1; add_summertime = 1;
else else
add_summertime = 0; add_summertime = 0;
}
// create a degree sign // create a degree sign
lcd.createChar(0, (uint8_t*)degree_sign); lcd.createChar(0, (uint8_t*)degree_sign);
@ -155,8 +158,21 @@ void setup()
void loop() void loop()
{ {
static uint32_t next_time_check;
sched.scheduler(); 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 WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects, if (client) { // If a new client connects,
@ -248,6 +264,8 @@ void loop()
} }
client.println("</h2>\n"); client.println("</h2>\n");
if (DateTime.isTimeValid())
{
DateTimeParts p = DateTime.getParts(); DateTimeParts p = DateTime.getParts();
char dt[21]; char dt[21];
@ -266,6 +284,7 @@ void loop()
else else
client.print(" Winterzeit\n"); client.print(" Winterzeit\n");
client.println("</h2>\n"); client.println("</h2>\n");
}
client.println("</center>\n"); client.println("</center>\n");
client.println("</body>\n"); client.println("</body>\n");
@ -327,9 +346,12 @@ void check_reset_ap_data(void)
void show_time(void) void show_time(void)
{ {
DateTimeParts p = DateTime.getParts();
char dt[21]; char dt[21];
if (DateTime.isTimeValid())
{
DateTimeParts p = DateTime.getParts();
if (p.getHours() == 0 && p.getMinutes() == 0 && p.getSeconds() == 0) if (p.getHours() == 0 && p.getMinutes() == 0 && p.getSeconds() == 0)
DateTime.forceUpdate(); DateTime.forceUpdate();
@ -347,7 +369,9 @@ void show_time(void)
DEBUG_MSG(" Summertime\n"); DEBUG_MSG(" Summertime\n");
else else
DEBUG_MSG(" Wintertime\n"); DEBUG_MSG(" Wintertime\n");
}
else
sprintf(dt, "--:--:---- --:--:--");
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.print(dt); lcd.print(dt);

Loading…
Cancel
Save