Implement absolute humidity calculation
This commit is contained in:
parent
3ab22b2e94
commit
31bf631365
@ -18,14 +18,18 @@
|
||||
#define TOPIC_HMID TOPIC_BASE "humidity"
|
||||
#define TOPIC_HEAT TOPIC_BASE "heat_index"
|
||||
#define TOPIC_AIRQ TOPIC_BASE "air_gas"
|
||||
#define TOPIC_ABHU TOPIC_BASE "abs_humidity"
|
||||
|
||||
#define DIFF_TEMP 0.3 // sensor has only 0.5°C accuracy, triggering on less is ludicrous
|
||||
#define DIFF_HMID 2.5 // humidity doesn't change that much anyways
|
||||
#define DIFF_HEAT 0.2 // this one's actually quite active
|
||||
#define DIFF_AIRQ 3 // this one hardly changes
|
||||
#define DIFF_ABHU 0.1 // small changes mean quite something
|
||||
|
||||
float hmid = 0; // humidity
|
||||
float hmid_r = 0; // humidity
|
||||
float abhu = 0; // absolute humidity
|
||||
float abhu_r = 0; // absolute humidity
|
||||
float temp = 0; // temperature
|
||||
float temp_r = 0; // temperature
|
||||
float heat = 0; // heat index
|
||||
@ -122,8 +126,6 @@ bool publish (String desc, char *topic, float val, float &lastVal, float diff, b
|
||||
Serial.print("** ERROR: Value out of bounds, not published. Last value :");
|
||||
Serial.println(String(lastVal).c_str());
|
||||
}
|
||||
} else {
|
||||
Serial.println("Not enough variation for a publication");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@ -181,6 +183,10 @@ void loop() {
|
||||
Serial.println("ERR: Sensor could not be identified");
|
||||
}
|
||||
|
||||
if (!isnan(hmid) && !isnan(temp)){
|
||||
abhu = (6.112 * ( pow(2.71828, ((17.67 * temp) / (temp + 243.5))) * hmid * 2.1674)) / (273.15 + temp);
|
||||
}
|
||||
|
||||
published = false;
|
||||
if (lastSent > FORCE_PERIOD) {
|
||||
Serial.println(F("Forcing a publish of all values"));
|
||||
@ -192,6 +198,7 @@ void loop() {
|
||||
published += publish("humidity", TOPIC_HMID, hmid, hmid_r, DIFF_HMID, forcePublish);
|
||||
published += publish("heat index", TOPIC_HEAT, heat, heat_r, DIFF_HEAT, forcePublish);
|
||||
published += publish("air quality", TOPIC_AIRQ, airq, airq_r, DIFF_AIRQ, forcePublish);
|
||||
published += publish("absolute humidity", TOPIC_ABHU, abhu, abhu_r, DIFF_ABHU, forcePublish);
|
||||
|
||||
if (published == false) {
|
||||
lastSent = lastSent + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user