filter nosiy measurement from dht22 with diffrence > 10 from average
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 9 May 2019 07:44:48 +0000 (09:44 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 9 May 2019 07:44:48 +0000 (09:44 +0200)
rpi_promini/rpi_promini.ino

index 5e98806..d767dd0 100644 (file)
@@ -114,11 +114,13 @@ unsigned long time = millis();
 void loop() {
   if ( millis() - time > 2000 ) {
     float t = dht.getTemperature();
 void loop() {
   if ( millis() - time > 2000 ) {
     float t = dht.getTemperature();
-    if ( dht.getStatus() == 0 )
+    float delta_t = abs(t - temp_avg.getAverage());
+    if ( dht.getStatus() == 0 && delta_t < 10 )
       temp_avg.addValue( t );
     else dht22_errors++;
     float h = dht.getHumidity();
       temp_avg.addValue( t );
     else dht22_errors++;
     float h = dht.getHumidity();
-    if ( dht.getStatus() == 0 )
+    float delta_h = abs(h - hum_avg.getAverage());
+    if ( dht.getStatus() == 0 && delta_h < 10 )
       hum_avg.addValue( h );
     else dht22_errors++;
     time = millis();
       hum_avg.addValue( h );
     else dht22_errors++;
     time = millis();