SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
dew_point.cpp
Go to the documentation of this file.
1#include "dew_point.h"
2
3#include <cmath>
4
5namespace sensesp {
6
7// dew point
8
9DewPoint::DewPoint() : Transform<std::tuple<float, float>, float>() {}
10
11void DewPoint::set(const std::tuple<float, float>& input) {
12 // Dew point is calculated with Arden Buck Equation and Arden Buck valuation
13 // sets For more info on the calculation see
14 // https://en.wikipedia.org/wiki/Dew_point#Calculating_the_dew_point
15
16 float const temp_celsius = std::get<0>(input) - 273.15;
17 float const relative_humidity = std::get<1>(input);
18
19 // valuation set for temperatures above 0°C
20 float b = 17.368;
21 float c = 238.88;
22 const float d = 234.5;
23
24 // valuation set for temperatures below 0°C
25 if (temp_celsius < 0.0) {
26 b = 17.966;
27 c = 247.15;
28 }
29
30 float gamma =
31 log(relative_humidity *
32 exp((b - (temp_celsius / d)) * (temp_celsius / (c + temp_celsius))));
33 float const dew_point = (c * gamma) / (b - gamma);
34
35 this->emit(dew_point + 273.15); // Kelvin is Celsius + 273.15
36}
37
38} // namespace sensesp
virtual void set(const std::tuple< float, float > &input) override
Definition dew_point.cpp:11
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:68
void emit(const T &new_value)