Several fixes for working with nan values.

master
Holger Wirtz 4 years ago
parent ceb4cb8faa
commit 18b2f17f14
  1. 53
      WLAN_Thermometer.ino

@ -48,7 +48,7 @@ DHT dht(TEMP_SENS_PIN, DHTTYPE);
const uint8_t degree_sign[8] = { B00010, B00101, B00010, B00000, B00000, B00000, B00000, B00000 }; const uint8_t degree_sign[8] = { B00010, B00101, B00010, B00000, B00000, B00000, B00000, B00000 };
uint8_t add_summertime = 0; uint8_t add_summertime = 0;
bool last_reset_ap_check = false; bool last_reset_ap_check = false;
bool minmax_enabled = false; //bool minmax_enabled = false;
char date_string_old[9]; char date_string_old[9];
enum { enum {
@ -240,48 +240,75 @@ void loop()
client.println("<center>"); client.println("<center>");
client.println("<h1 style=\"color:green;\">Temperatur</h1>"); client.println("<h1 style=\"color:green;\">Temperatur</h1>");
client.print("<h2 style=\"color:green;\">Aktuell: "); client.print("<h2 style=\"color:green;\">Aktuell: ");
if (!isnan(temp[ACT]))
client.print(temp[ACT]); client.print(temp[ACT]);
else
client.print("--.--");
client.println(" &deg;C</h2>"); client.println(" &deg;C</h2>");
if (millis() > FIRST_MIN_MAX) if (millis() > FIRST_MIN_MAX)
{ {
client.print("<h2 style=\"color:green;\">Minimum: "); client.print("<h2 style=\"color:green;\">Minimum: ");
if (!isnan(temp[MIN]))
client.print(temp[MIN]); client.print(temp[MIN]);
else
client.print("--.--");
client.print(" &deg;C"); client.print(" &deg;C");
client.print("</h2>\n"); client.print("</h2>\n");
client.print("<h2 style=\"color:green;\">Maximum: "); client.print("<h2 style=\"color:green;\">Maximum: ");
if (!isnan(temp[MAX]))
client.print(temp[MAX]); client.print(temp[MAX]);
else
client.print("--.--");
client.print(" &deg;C"); client.print(" &deg;C");
client.println("</h2>"); client.println("</h2>");
} }
client.println("<hr>"); client.println("<hr>");
client.println("<h1 style=\"color:red;\">Gef&uuml;hlte Temperatur</h1>"); client.println("<h1 style=\"color:red;\">Gef&uuml;hlte Temperatur</h1>");
client.print("<h2 style=\"color:red;\">Aktuell: "); client.print("<h2 style=\"color:red;\">Aktuell: ");
if (!isnan(heat[ACT]))
client.print(heat[ACT]); client.print(heat[ACT]);
else
client.print("--.--");
client.println(" &deg;C</h2>"); client.println(" &deg;C</h2>");
if (millis() > FIRST_MIN_MAX) if (millis() > FIRST_MIN_MAX)
{ {
client.print("<h2 style=\"color:red;\">Minimum: "); client.print("<h2 style=\"color:red;\">Minimum: ");
if (!isnan(heat[MIN]))
client.print(heat[MIN]); client.print(heat[MIN]);
else
client.print("--.--");
client.print(" &deg;C"); client.print(" &deg;C");
client.println("</h2>"); client.println("</h2>");
client.print("<h2 style=\"color:red;\">Maximum: "); client.print("<h2 style=\"color:red;\">Maximum: ");
if (!isnan(heat[MAX]))
client.print(heat[MAX]); client.print(heat[MAX]);
else
client.print("--.--");
client.print(" &deg;C"); client.print(" &deg;C");
client.println("</h2>"); client.println("</h2>");
} }
client.println("<hr>"); client.println("<hr>");
client.println("<h1 style=\"color:blue;\">Luftfeuchtigkeit</h1>"); client.println("<h1 style=\"color:blue;\">Luftfeuchtigkeit</h1>");
client.print("<h2 style=\"color:blue;\">Aktuell: "); client.print("<h2 style=\"color:blue;\">Aktuell: ");
if (!isnan(hum[ACT]))
client.print(hum[ACT]); client.print(hum[ACT]);
else
client.print("--.--");
client.println(" %</h2>"); client.println(" %</h2>");
if (millis() > FIRST_MIN_MAX) if (millis() > FIRST_MIN_MAX)
{ {
client.print("<h2 style=\"color:blue;\">Minimum: "); client.print("<h2 style=\"color:blue;\">Minimum: ");
if (!isnan(hum[MIN]))
client.print(hum[MIN]); client.print(hum[MIN]);
else
client.print("--.--");
client.print(" %"); client.print(" %");
client.println("</h2>"); client.println("</h2>");
client.print("<h2 style=\"color:blue;\">Maximum: "); client.print("<h2 style=\"color:blue;\">Maximum: ");
if (!isnan(hum[MAX]))
client.print(hum[MAX]); client.print(hum[MAX]);
else
client.print("--.--");
client.print(" %"); client.print(" %");
client.println("</h2>"); client.println("</h2>");
} }
@ -319,7 +346,7 @@ void loop()
client.println("WWW-Authenticate: Basic realm=\"Secure\""); client.println("WWW-Authenticate: Basic realm=\"Secure\"");
client.println("Content-Type: text/html"); client.println("Content-Type: text/html");
client.println(); client.println();
client.println("<html>Authentication failed</html>"); client.println("<html>Authentification failed</html>");
break; break;
} }
} else { // if you got a newline, then clear currentLine } else { // if you got a newline, then clear currentLine
@ -500,6 +527,7 @@ void get_sensor_data(void)
else else
heat[ACT] = NAN; heat[ACT] = NAN;
/*
if (minmax_enabled == false && millis() > FIRST_MIN_MAX) if (minmax_enabled == false && millis() > FIRST_MIN_MAX)
minmax_enabled = true; minmax_enabled = true;
@ -525,8 +553,15 @@ void get_sensor_data(void)
} }
else else
{ {
*/
if (!isnan(temp[ACT])) if (!isnan(temp[ACT]))
{ {
if (isnan(temp[MIN]))
temp[MIN] = temp[ACT];
if (isnan(temp[MAX]))
temp[MAX] = temp[ACT];
if (temp[ACT] < temp[MIN]) if (temp[ACT] < temp[MIN])
temp[MIN] = temp[ACT]; temp[MIN] = temp[ACT];
else if (temp[ACT] > temp[MAX]) else if (temp[ACT] > temp[MAX])
@ -535,6 +570,12 @@ void get_sensor_data(void)
if (!isnan(hum[ACT])) if (!isnan(hum[ACT]))
{ {
if (isnan(hum[MIN]))
hum[MIN] = hum[ACT];
if (isnan(hum[MAX]))
hum[MAX] = hum[ACT];
if (hum[ACT] < hum[MIN]) if (hum[ACT] < hum[MIN])
hum[MIN] = hum[ACT]; hum[MIN] = hum[ACT];
else if (hum[ACT] > hum[MAX]) else if (hum[ACT] > hum[MAX])
@ -543,12 +584,18 @@ void get_sensor_data(void)
if (!isnan(heat[ACT])) if (!isnan(heat[ACT]))
{ {
if (isnan(heat[MIN]))
heat[MIN] = heat[ACT];
if (isnan(heat[MAX]))
heat[MAX] = heat[ACT];
if (heat[ACT] < heat[MIN]) if (heat[ACT] < heat[MIN])
heat[MIN] = heat[ACT]; heat[MIN] = heat[ACT];
else if (heat[ACT] > heat[MAX]) else if (heat[ACT] > heat[MAX])
heat[MAX] = heat[ACT]; heat[MAX] = heat[ACT];
} }
} //}
} }
void ConfigAPWeb(void) void ConfigAPWeb(void)

Loading…
Cancel
Save