Above sketch is working great: 6 temperatures of a hot water boiler can be monitored in order to decide when to pump excess (solar or woodfire) energy to another boiler.
But as you can see, the sampling rate is every 5’ and now and then (interval = 4 - 10 h) an “odd” value is read:
This makes the system unreliable…
In order to mitigate these errors, I have constrained the values within fixed minimum/maximum margins in the loop() function of above sketch:
void loop()
{
getTemperatures(0);
// Constrain the 6 temperatures between 20 - 80:
TopH = constrain(TopH, 20, 80);
TopL = constrain(TopL, 20, 80);
MidH = constrain(MidH, 20, 80);
MidL = constrain(MidL, 17, 80);
BotH = constrain(BotH, 17, 80);
BotL = constrain(BotL, 17, 80);
// TO DO: Limit or ignore the incorrect readings! For example: Constrain the temperatures between + and - 1 degree from previously known correct value... How can this be done in this sketch? (The Particle.publish function will publish them anyway...???
// Calculate the average temperature in each of the 5 zones:
Av1 = (TopH + TopL)/2;
Av2 = (TopL + MidH)/2;
Av3 = (MidH + MidL)/2;
Av4 = (MidL + BotH)/2;
Av5 = (BotH + BotL)/2;
// Calculate the "spare" energy in each of the 5 zones:
Q1 = (Av1-Tmin)*110*1.163/1000; // Spare energy in 110 liter top zone (kWh)
Q2 = (Av2-Tmin)*90*1.163/1000; // Spare energy in 90 liter top/mid zone (kWh)
Q3 = (Av3-Tmin)*90*1.163/1000; // Spare energy in 90 liter middle zone (kWh)
Q4 = (Av4-Tmin)*90*1.163/1000; // Spare energy in 90 liter mid/bottom zone (kWh)
Q5 = (Av5-Tmin)*110*1.163/1000; // Spare energy in 110 liter bottom zone (kWh)
Qtot = Q1+Q2+Q3+Q4+Q5; // Total spare energy in Buffer (kWh)
// Constrain Qtot between 0 - 30:
Qtot = constrain(Qtot, 0, 30);
delay(5000);
}
Still, the values fluctuate too much at times. And of course, I can not constrain the values more than the ‘normal’ values we can expect to read…
Does anyone know a simple method I could use in above (yesterday’s) sketch to NOT publish any of the temperatures to the “Particle.variables” if one of the 6 is more than 1 degree higher or lower than the previous correct value?
PS: I found a few related threads like this one: LINK1 by @ethelder or LINK2 by @mdma but don’t know which the best practice to follow…
Anybody with experience in filtering DS18x20 data?