From 18b2f17f147a681463c220285a4788850386cc8b Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 20 Nov 2020 10:50:05 +0100 Subject: [PATCH] Several fixes for working with nan values. --- WLAN_Thermometer.ino | 139 +++++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 46 deletions(-) diff --git a/WLAN_Thermometer.ino b/WLAN_Thermometer.ino index b1b9c86..50bded1 100644 --- a/WLAN_Thermometer.ino +++ b/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 }; uint8_t add_summertime = 0; bool last_reset_ap_check = false; -bool minmax_enabled = false; +//bool minmax_enabled = false; char date_string_old[9]; enum { @@ -240,48 +240,75 @@ void loop() client.println("
"); client.println("

Temperatur

"); client.print("

Aktuell: "); - client.print(temp[ACT]); + if (!isnan(temp[ACT])) + client.print(temp[ACT]); + else + client.print("--.--"); client.println(" °C

"); if (millis() > FIRST_MIN_MAX) { client.print("

Minimum: "); - client.print(temp[MIN]); + if (!isnan(temp[MIN])) + client.print(temp[MIN]); + else + client.print("--.--"); client.print(" °C"); client.print("

\n"); client.print("

Maximum: "); - client.print(temp[MAX]); + if (!isnan(temp[MAX])) + client.print(temp[MAX]); + else + client.print("--.--"); client.print(" °C"); client.println("

"); } client.println("
"); client.println("

Gefühlte Temperatur

"); client.print("

Aktuell: "); - client.print(heat[ACT]); + if (!isnan(heat[ACT])) + client.print(heat[ACT]); + else + client.print("--.--"); client.println(" °C

"); if (millis() > FIRST_MIN_MAX) { client.print("

Minimum: "); - client.print(heat[MIN]); + if (!isnan(heat[MIN])) + client.print(heat[MIN]); + else + client.print("--.--"); client.print(" °C"); client.println("

"); client.print("

Maximum: "); - client.print(heat[MAX]); + if (!isnan(heat[MAX])) + client.print(heat[MAX]); + else + client.print("--.--"); client.print(" °C"); client.println("

"); } client.println("
"); client.println("

Luftfeuchtigkeit

"); client.print("

Aktuell: "); - client.print(hum[ACT]); + if (!isnan(hum[ACT])) + client.print(hum[ACT]); + else + client.print("--.--"); client.println(" %

"); if (millis() > FIRST_MIN_MAX) { client.print("

Minimum: "); - client.print(hum[MIN]); + if (!isnan(hum[MIN])) + client.print(hum[MIN]); + else + client.print("--.--"); client.print(" %"); client.println("

"); client.print("

Maximum: "); - client.print(hum[MAX]); + if (!isnan(hum[MAX])) + client.print(hum[MAX]); + else + client.print("--.--"); client.print(" %"); client.println("

"); } @@ -319,7 +346,7 @@ void loop() client.println("WWW-Authenticate: Basic realm=\"Secure\""); client.println("Content-Type: text/html"); client.println(); - client.println("Authentication failed"); + client.println("Authentification failed"); break; } } else { // if you got a newline, then clear currentLine @@ -500,55 +527,75 @@ void get_sensor_data(void) else heat[ACT] = NAN; - if (minmax_enabled == false && millis() > FIRST_MIN_MAX) + /* + if (minmax_enabled == false && millis() > FIRST_MIN_MAX) minmax_enabled = true; - if (minmax_enabled == false) - { - if (!isnan(temp[ACT])) + if (minmax_enabled == false) + { + if (!isnan(temp[ACT])) + { + temp[MIN] = temp[ACT]; + temp[MAX] = temp[ACT]; + } + + if (!isnan(hum[ACT])) + { + hum[MIN] = hum[ACT]; + hum[MAX] = hum[ACT]; + } + + if (!isnan(heat[ACT])) + { + heat[MIN] = heat[ACT]; + heat[MIN] = heat[ACT]; + } + } + else { + */ + if (!isnan(temp[ACT])) + { + if (isnan(temp[MIN])) temp[MIN] = temp[ACT]; + + if (isnan(temp[MAX])) temp[MAX] = temp[ACT]; - } - if (!isnan(hum[ACT])) - { + if (temp[ACT] < temp[MIN]) + temp[MIN] = temp[ACT]; + else if (temp[ACT] > temp[MAX]) + temp[MAX] = temp[ACT]; + } + + if (!isnan(hum[ACT])) + { + if (isnan(hum[MIN])) hum[MIN] = hum[ACT]; + + if (isnan(hum[MAX])) hum[MAX] = hum[ACT]; - } - if (!isnan(heat[ACT])) - { - heat[MIN] = heat[ACT]; - heat[MIN] = heat[ACT]; - } + if (hum[ACT] < hum[MIN]) + hum[MIN] = hum[ACT]; + else if (hum[ACT] > hum[MAX]) + hum[MAX] = hum[ACT]; } - else + + if (!isnan(heat[ACT])) { - if (!isnan(temp[ACT])) - { - if (temp[ACT] < temp[MIN]) - temp[MIN] = temp[ACT]; - else if (temp[ACT] > temp[MAX]) - temp[MAX] = temp[ACT]; - } + if (isnan(heat[MIN])) + heat[MIN] = heat[ACT]; - if (!isnan(hum[ACT])) - { - if (hum[ACT] < hum[MIN]) - hum[MIN] = hum[ACT]; - else if (hum[ACT] > hum[MAX]) - hum[MAX] = hum[ACT]; - } + if (isnan(heat[MAX])) + heat[MAX] = heat[ACT]; - if (!isnan(heat[ACT])) - { - if (heat[ACT] < heat[MIN]) - heat[MIN] = heat[ACT]; - else if (heat[ACT] > heat[MAX]) - heat[MAX] = heat[ACT]; - } + if (heat[ACT] < heat[MIN]) + heat[MIN] = heat[ACT]; + else if (heat[ACT] > heat[MAX]) + heat[MAX] = heat[ACT]; } + //} } void ConfigAPWeb(void)