SensESP 2.7.2
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
10 inputs[inputChannel] = input;
11 received |= 1 << inputChannel;
12 if (received ==
13 0b11) { // for 2 channels, use 0b11. For 3 channels, use b111 and so on.
14 received = 0; // recalculates after all values are updated. Remove if a
15 // recalculation is required after an update of any value.
16
17 // The following equation approximate the heat index
18 // using both Steadman's and Rothfusz equations
19 // See https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3801457/
20 // Algorithm 1 (table 1) (algorithm in figure 3)
21
22 float temp_fahrenheit = 1.8 * (inputs[0] - 273.15) +
23 32; // dry-bulb temperature in degrees fahrenheit
24 float relative_humidity = inputs[1] * 100; // relative humidity in percent
25
26 // step 1: if temperature is less than 40°F then heat index temperature is
27 // dry bulb temperature.
29
30 if (temp_fahrenheit <= 40) {
32 } else {
33 // step 2: use algorithm to calculate heat index and us it if the result
34 // is less than 79°F;
36 -10.3 + 1.1 * temp_fahrenheit + 0.047 * relative_humidity;
37 if (heat_index_temperature > 79) {
38 // step 3: calculate heat index temperature for other temperatures
39 // Coefficients for temperature in Fahrenheit
40 const double c1 = -42.379;
41 const double c2 = 2.04901523;
42 const double c3 = 10.14333127;
43 const double c4 = -0.22475541;
44 const double c5 = -0.00683783;
45 const double c6 = -0.05481717;
46 const double c7 = 0.00122874;
47 const double c8 = 0.00085282;
48 const double c9 = -0.00000199;
49
50 // equation for heat index
58
59 // step 4: if humidity =< 13% and temp between 80°F and 112°F then
60 // correct heat index temperature
61 if (relative_humidity <= 13 && 80 <= temp_fahrenheit &&
62 temp_fahrenheit <= 112) {
65 ((13 - relative_humidity) / 4) *
66 sqrt(17 - abs(temp_fahrenheit - 95) / 17);
67 }
68
69 // step 5: if humidity => 85% and temp between 80°C and 87°C then
70 // correct heat index temperature
71 else if (relative_humidity > 85 && 80 <= temp_fahrenheit &&
72 temp_fahrenheit <= 87) {
75 0.02 * (relative_humidity - 85) * (87 - temp_fahrenheit);
76 }
77 }
78 }
79
80 this->emit((heat_index_temperature - 32) / 1.8 +
81 273.15); // Fahrenheit to Kelvin
82 }
83}
84
85// heat index effect (warning levels)
86
88
90 float heat_index_temperature = input - 273.15; // celsius = kelvin - 273.15
92 if (heat_index_temperature > 54) {
93 heat_index_effect = "Extreme danger";
94 } else if (heat_index_temperature > 41) {
95 heat_index_effect = "Danger";
96 } else if (heat_index_temperature > 32) {
97 heat_index_effect = "Extreme Caution";
98 } else if (heat_index_temperature > 27) {
99 heat_index_effect + "Caution";
100 }
101
102 this->emit(heat_index_effect);
103}
104
105} // namespace sensesp
virtual void set_input(float input, uint8_t inputChannel=0) override
virtual void set_input(float input, uint8_t inputChannel) override
Definition heat_index.cpp:9
Construct a new transform based on a single function.
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:54