Compare commits
2 Commits
3cc9c62696
...
2b94a8c12b
Author | SHA1 | Date | |
---|---|---|---|
2b94a8c12b | |||
fffde16271 |
@ -21,10 +21,10 @@
|
|||||||
#define TOPIC_ABHU TOPIC_BASE "abs_humidity"
|
#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_TEMP 0.3 // sensor has only 0.5°C accuracy, triggering on less is ludicrous
|
||||||
#define DIFF_HMID 1.5 // humidity doesn't change that much anyways
|
#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_HEAT 0.3 // this one's actually quite active
|
||||||
#define DIFF_AIRQ 3 // this one hardly changes
|
#define DIFF_AIRQ 3 // this one hardly changes
|
||||||
#define DIFF_ABHU 0.1 // small changes mean quite something
|
#define DIFF_ABHU 0.2 // small changes mean quite something
|
||||||
|
|
||||||
float hmid = 0; // humidity
|
float hmid = 0; // humidity
|
||||||
float hmid_r = 0; // humidity
|
float hmid_r = 0; // humidity
|
||||||
@ -105,7 +105,7 @@ bool checkVariation(float newValue, float prevValue, float maxDiff) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool checkPlausibility(float newValue, float prevValue, float maxDiff) {
|
bool checkPlausibility(float newValue, float prevValue, float maxDiff) {
|
||||||
return (newValue < prevValue + (maxDiff * 10) || newValue > prevValue - (maxDiff * 10));
|
return (newValue < prevValue + (maxDiff * 10) || newValue > prevValue - (maxDiff * 10) || lastVal == 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
long lastMsg = 0;
|
long lastMsg = 0;
|
||||||
@ -115,16 +115,18 @@ bool forcePublish = false;
|
|||||||
|
|
||||||
bool publish (String desc, char *topic, float val, float &lastVal, float diff, bool force){
|
bool publish (String desc, char *topic, float val, float &lastVal, float diff, bool force){
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
Serial.println("Sample " + desc + ": " + String(val).c_str());
|
Serial.println("Sample " + desc + ": " + String(val).c_str() + " vs. last " + String(lastVal).c_str());
|
||||||
if (checkVariation(val, lastVal, diff) or force) {
|
if (checkVariation(val, lastVal, diff) or force) {
|
||||||
Serial.println("Sufficient variation on " + desc + ": " + String(val).c_str());
|
Serial.println("Sufficient variation on " + desc + ": " + String(val).c_str());
|
||||||
if (checkPlausibility(val, lastVal, diff) or force) {
|
if (checkPlausibility(val, lastVal, diff) or force) {
|
||||||
Serial.println("Value published");
|
if (lastVal != 0.0) {
|
||||||
|
val = (lastVal*2 + val) / 3; // slight averaging
|
||||||
|
}
|
||||||
|
Serial.println("Value " + desc + " averaged and published : " + String(val).c_str());
|
||||||
client.publish(topic, String(val).c_str(), true);
|
client.publish(topic, String(val).c_str(), true);
|
||||||
ret = true;
|
ret = true;
|
||||||
} else {
|
} else {
|
||||||
Serial.print("** ERROR: Value out of bounds, not published. Last value :");
|
Serial.println("** ERROR: Value " + desc + " out of bounds, not published. Last : " + String(lastVal).c_str());
|
||||||
Serial.println(String(lastVal).c_str());
|
|
||||||
}
|
}
|
||||||
lastVal = val;
|
lastVal = val;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user