From b31c487b33f0c3e180fb26740650c0f6c8e06936 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Thu, 6 Jan 2022 15:32:26 +0100 Subject: [PATCH] 0.3.0 Temperature --- libraries/Temperature/.arduino-ci.yml | 10 +-- .../heatindex_table/heatindex_table.ino | 5 +- libraries/Temperature/library.json | 2 +- libraries/Temperature/library.properties | 2 +- libraries/Temperature/readme.md | 15 +++++ libraries/Temperature/temperature.h | 66 +++++++++++++------ libraries/Temperature/test/unit_test_001.cpp | 8 ++- 7 files changed, 77 insertions(+), 31 deletions(-) diff --git a/libraries/Temperature/.arduino-ci.yml b/libraries/Temperature/.arduino-ci.yml index 3e496624..cecf5850 100644 --- a/libraries/Temperature/.arduino-ci.yml +++ b/libraries/Temperature/.arduino-ci.yml @@ -2,10 +2,10 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - due - - zero - - leonardo + # - due + # - zero + # - leonardo - m4 - esp32 - - esp8266 - - mega2560 + # - esp8266 + # - mega2560 diff --git a/libraries/Temperature/examples/heatindex_table/heatindex_table.ino b/libraries/Temperature/examples/heatindex_table/heatindex_table.ino index 029db2ab..75af7d79 100644 --- a/libraries/Temperature/examples/heatindex_table/heatindex_table.ino +++ b/libraries/Temperature/examples/heatindex_table/heatindex_table.ino @@ -17,7 +17,9 @@ void setup() Serial.println(__FILE__); Serial.println(); - + Serial.println(" Compare to: https://www.calculator.net/heat-index-calculator.html\n"); + Serial.println(); + for (int t = 80; t <= 110; t += 2) { Serial.print("\t"); @@ -50,4 +52,3 @@ void loop() // -- END OF FILE -- - diff --git a/libraries/Temperature/library.json b/libraries/Temperature/library.json index 0e3ec485..6eeafb48 100644 --- a/libraries/Temperature/library.json +++ b/libraries/Temperature/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Temperature" }, - "version": "0.2.5", + "version": "0.3.0", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/Temperature/library.properties b/libraries/Temperature/library.properties index d42217e4..5f70f196 100644 --- a/libraries/Temperature/library.properties +++ b/libraries/Temperature/library.properties @@ -1,5 +1,5 @@ name=Temperature -version=0.2.5 +version=0.3.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library with weather related functions. diff --git a/libraries/Temperature/readme.md b/libraries/Temperature/readme.md index d651178d..22461d9b 100644 --- a/libraries/Temperature/readme.md +++ b/libraries/Temperature/readme.md @@ -42,6 +42,21 @@ DHT22 or Sensirion, to make a weather station application. - **float heatIndex(float Fahrenheit, float humidity)** idem. - **float heatIndexC(float Celsius, float humidity)** idem. +**0.3.0** +The formula for the **heatIndex()** was taken from https://en.wikipedia.org/wiki/Heat_index. +Since version 0.3.0 the more elaborated version of https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +will be used. Note: there will be performance differences. + +Indicative table + +| Fahrenheit | Celsius | description | colour code | +|:----------:|:-------:|:------------|------------:| +| 70-79 | 21-26 | warm | green | +| 80-89 | 26-32 | very warm | yellow | +| 90-104 | 32-40 | hot | orange | +| 105-129 | 40-54 | very hot | red | +| > 130 | > 54 | extreme hot | purple | + ### WindChill diff --git a/libraries/Temperature/temperature.h b/libraries/Temperature/temperature.h index 6a30ddc8..92b11e8f 100644 --- a/libraries/Temperature/temperature.h +++ b/libraries/Temperature/temperature.h @@ -1,7 +1,7 @@ #pragma once // // FILE: temperature.h -// VERSION: 0.2.5 +// VERSION: 0.3.0 // DATE: 2015-03-29 // PURPOSE: collection temperature functions // @@ -16,9 +16,11 @@ // 0.2.3 2020-08-27 fix #5 order of functions, typo, fixed 1 example // 0.2.4 2021-01-08 Arduino-CI + unit tests // 0.2.5 2021-12-28 Arduino-CI, library.json, readme.md, license, minor edits +// 0.3.0 2022-01-05 fix #10 update HeatIndex function +// compared with https://www.calculator.net/heat-index-calculator.html -#define TEMPERATURE_VERSION (F("0.2.5")) +#define TEMPERATURE_VERSION (F("0.3.0")) inline float Fahrenheit(float celsius) @@ -87,34 +89,59 @@ float humidex(float celsius, float dewPoint) } -// https://en.wikipedia.org/wiki/Heat_index +// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +// previous https://en.wikipedia.org/wiki/Heat_index // TODO add valid range for TF & R // TF = temp in Fahrenheit -// R = humidity in % -float heatIndex(float TF, float R) +// RH = relative humidity in % +float heatIndex(float TF, float RH) { - const float c1 = -42.379; - const float c2 = 2.04901523; - const float c3 = 10.14333127; - const float c4 = -0.22475541; - const float c5 = -0.00683783; - const float c6 = -0.05481717; - const float c7 = 0.00122874; - const float c8 = 0.00085282; - const float c9 = -0.00000199; + float HI = 0; - float A = (( c5 * TF) + c2) * TF + c1; - float B = (((c7 * TF) + c4) * TF + c3) * R; - float C = (((c9 * TF) + c8) * TF + c6) * R * R; + if (TF >= 80) + { + const float c1 = -42.379; + const float c2 = 2.04901523; + const float c3 = 10.14333127; + const float c4 = -0.22475541; + const float c5 = -0.00683783; + const float c6 = -0.05481717; + const float c7 = 0.00122874; + const float c8 = 0.00085282; + const float c9 = -0.00000199; - return A + B + C; + float A = (( c5 * TF) + c2) * TF + c1; + float B = (((c7 * TF) + c4) * TF + c3) * RH; + float C = (((c9 * TF) + c8) * TF + c6) * RH * RH; + + HI = A + B + C; + if ((RH < 13) && (TF <= 112)) + { + HI += ((13 - RH) / 4) * sqrt((17 - abs(TF - 95.0)) / 17); + } + if ((RH > 87) && (TF < 87)) + { + HI += ((RH - 85) / 10) * ((87 - TF) / 5); + } + return HI; + } + + HI = 0.5 * (TF + 61.0 + ((TF - 68.0) * 1.2) + (RH * 0.094)); + + return HI; } -// https://en.wikipedia.org/wiki/Heat_index +// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml +// previous https://en.wikipedia.org/wiki/Heat_index // TODO add valid range for TF & R +// TODO optimize? float heatIndexC(float celcius, float humidity) { + float TF = celcius * (9.0 / 5.0) + 32; + float HI = (heatIndex(TF, humidity) - 32) * (5.0 / 9.0); + return HI; +/* const float c1 = -8.78469475556; const float c2 = 1.61139411; const float c3 = 2.33854883889; @@ -130,6 +157,7 @@ float heatIndexC(float celcius, float humidity) float C = (((c9 * celcius) + c8) * celcius + c6) * humidity * humidity; return A + B + C; +*/ } diff --git a/libraries/Temperature/test/unit_test_001.cpp b/libraries/Temperature/test/unit_test_001.cpp index 2ebfadc0..e776a884 100644 --- a/libraries/Temperature/test/unit_test_001.cpp +++ b/libraries/Temperature/test/unit_test_001.cpp @@ -67,9 +67,11 @@ unittest(test_dewpoint) unittest(test_heatIndex) { - assertEqualFloat(206.46, heatIndex(20, 50), 0.001); - assertEqualFloat(77.3509, heatIndex(68, 50), 0.001); - assertEqualFloat(25.1949, heatIndexC(20, 50), 0.001); + // Fahrenheit + assertEqualFloat(14.050, heatIndex(20, 50), 0.001); + assertEqualFloat(66.850, heatIndex(68, 50), 0.001); + // Celsius + assertEqualFloat(19.361, heatIndexC(20, 50), 0.001); }