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
3
namespace
sensesp
{
4
5
// heat index temperature
6
7
HeatIndexTemperature::HeatIndexTemperature
() :
FloatTransform
() {}
8
9
void
HeatIndexTemperature::set_input
(
float
input,
uint8_t
inputChannel
) {
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.
28
float
heat_index_temperature
;
29
30
if
(
temp_fahrenheit
<= 40) {
31
heat_index_temperature
=
temp_fahrenheit
;
32
}
else
{
33
// step 2: use algorithm to calculate heat index and us it if the result
34
// is less than 79°F;
35
heat_index_temperature
=
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
51
float
heat_index_temperature
=
52
c1
+
c2
*
temp_fahrenheit
+
c3
*
relative_humidity
+
53
c4
*
temp_fahrenheit
*
relative_humidity
+
54
c5
*
pow
(
temp_fahrenheit
, 2) +
c6
*
pow
(
relative_humidity
, 2) +
55
c7
*
pow
(
temp_fahrenheit
, 2) *
relative_humidity
+
56
c8
*
temp_fahrenheit
*
pow
(
relative_humidity
, 2) +
57
c9
*
pow
(
temp_fahrenheit
, 2) *
pow
(
relative_humidity
, 2);
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) {
63
heat_index_temperature
=
64
heat_index_temperature
-
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) {
73
heat_index_temperature
=
74
heat_index_temperature
+
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
87
HeatIndexEffect::HeatIndexEffect
() :
Transform
<
float
,
String
>() {}
88
89
void
HeatIndexEffect::set_input
(
float
input,
uint8_t
inputChannel
) {
90
float
heat_index_temperature
= input - 273.15;
// celsius = kelvin - 273.15
91
String
heat_index_effect
=
""
;
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
sensesp::HeatIndexEffect::set_input
virtual void set_input(float input, uint8_t inputChannel=0) override
Definition
heat_index.cpp:89
sensesp::HeatIndexEffect::HeatIndexEffect
HeatIndexEffect()
Definition
heat_index.cpp:87
sensesp::HeatIndexTemperature::HeatIndexTemperature
HeatIndexTemperature()
Definition
heat_index.cpp:7
sensesp::HeatIndexTemperature::set_input
virtual void set_input(float input, uint8_t inputChannel) override
Definition
heat_index.cpp:9
sensesp::LambdaTransform
Construct a new transform based on a single function.
Definition
lambda_transform.h:71
sensesp::SymmetricTransform< float >
sensesp::Transform
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition
transform.h:54
sensesp::ValueProducer< P >::emit
void emit(P new_value)
Definition
valueproducer.h:109
heat_index.h
sensesp
Definition
sensesp.h:22
src
sensesp
transforms
heat_index.cpp
Generated by
1.9.8