SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
heat_index.cpp
Go to the documentation of this file.
1#include "heat_index.h"
2
3namespace sensesp {
4
5// heat index temperature
6
8
9void HeatIndexTemperature::set(const float& /*input*/) {
10 // The following equation approximate the heat index
11 // using both Steadman's and Rothfusz equations
12 // See https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3801457/
13 // Algorithm 1 (table 1) (algorithm in figure 3)
14
15 float const temp_fahrenheit =
16 1.8 * (inputs[0] - 273.15) +
17 32; // dry-bulb temperature in degrees fahrenheit
18 float const relative_humidity =
19 inputs[1] * 100; // relative humidity in percent
20
21 // step 1: if temperature is less than 40°F then heat index temperature is
22 // dry bulb temperature.
23 float heat_index_temperature;
24
25 if (temp_fahrenheit <= 40) {
26 heat_index_temperature = temp_fahrenheit;
27 } else {
28 // step 2: use algorithm to calculate heat index and us it if the result
29 // is less than 79°F;
30 heat_index_temperature =
31 -10.3 + 1.1 * temp_fahrenheit + 0.047 * relative_humidity;
32 if (heat_index_temperature > 79) {
33 // step 3: calculate heat index temperature for other temperatures
34 // Coefficients for temperature in Fahrenheit
35 const float c1 = -42.379;
36 const float c2 = 2.04901523;
37 const float c3 = 10.14333127;
38 const float c4 = -0.22475541;
39 const float c5 = -0.00683783;
40 const float c6 = -0.05481717;
41 const float c7 = 0.00122874;
42 const float c8 = 0.00085282;
43 const float c9 = -0.00000199;
44
45 // equation for heat index
46 float heat_index_temperature =
47 c1 + c2 * temp_fahrenheit + c3 * relative_humidity +
48 c4 * temp_fahrenheit * relative_humidity +
49 c5 * pow(temp_fahrenheit, 2) + c6 * pow(relative_humidity, 2) +
50 c7 * pow(temp_fahrenheit, 2) * relative_humidity +
51 c8 * temp_fahrenheit * pow(relative_humidity, 2) +
52 c9 * pow(temp_fahrenheit, 2) * pow(relative_humidity, 2);
53
54 // step 4: if humidity =< 13% and temp between 80°F and 112°F then
55 // correct heat index temperature
56 if (relative_humidity <= 13 && 80 <= temp_fahrenheit &&
57 temp_fahrenheit <= 112) {
58 heat_index_temperature = heat_index_temperature -
59 ((13 - relative_humidity) / 4) *
60 sqrt(17 - abs(temp_fahrenheit - 95) / 17);
61 }
62
63 // step 5: if humidity => 85% and temp between 80°C and 87°C then
64 // correct heat index temperature
65 else if (relative_humidity > 85 && 80 <= temp_fahrenheit &&
66 temp_fahrenheit <= 87) {
67 heat_index_temperature =
68 heat_index_temperature +
69 0.02 * (relative_humidity - 85) * (87 - temp_fahrenheit);
70 }
71 }
72
73 this->emit((heat_index_temperature - 32) / 1.8 +
74 273.15); // Fahrenheit to Kelvin
75 }
76}
77
78// heat index effect (warning levels)
79
81
82void HeatIndexEffect::set(const float& input) {
83 const float heat_index_temperature =
84 input - 273.15; // celsius = kelvin - 273.15
85 String heat_index_effect = "";
86 if (heat_index_temperature > 54) {
87 heat_index_effect = "Extreme danger";
88 } else if (heat_index_temperature > 41) {
89 heat_index_effect = "Danger";
90 } else if (heat_index_temperature > 32) {
91 heat_index_effect = "Extreme Caution";
92 } else if (heat_index_temperature > 27) {
93 heat_index_effect + "Caution";
94 }
95
96 this->emit(heat_index_effect);
97}
98
99} // namespace sensesp
virtual void set(const float &input) override
virtual void set(const float &input) override
Definition heat_index.cpp:9
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
void emit(const float &new_value)