]> dxcluster.org Git - dweather.git/commitdiff
add some range checking...
authorDirk Koopman <djk@tobit.co.uk>
Tue, 20 Jan 2015 20:24:49 +0000 (20:24 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Tue, 20 Jan 2015 20:24:49 +0000 (20:24 +0000)
loop.pl

diff --git a/loop.pl b/loop.pl
index ca85bbd9671ddfc59da24fc7961d7fd9ba819348..30bea05397d4b20a234a2db2a34e1cf8c748b2fa 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -297,16 +297,32 @@ sub process
 
                $temp  = nearest(0.1, f2c(unpack("s", substr $blk,12,2) / 10));
                $h{Temp_Out}  = $temp;
+               if ($temp > 75 || $temp < -75) {
+                       dbg "LOOP Temperature out of range ($temp), record ignored";
+                       return;
+               }
 
                $tmp = unpack("C", substr $blk,14,1);
                $h{Wind} = nearest(0.1, mph2mps($tmp));
                $h{Dir}     = unpack("s", substr $blk,16,2)+0;
 
                my $wind = {w => $h{Wind}, d => $h{Dir}};
+               $wind = 0 if $wind == 255;
                push @{$ld->{wind_min}}, $wind;
 
-               $h{Humidity_Out} = unpack("C", substr $blk,33,1)+0;
-               $h{Humidity_In}  = unpack("C", substr $blk,11,1)+0;
+               $tmp = int(unpack("C", substr $blk,33,1)+0);
+               if ($tmp > 100) {
+                       dbg "LOOP Outside Humidity out of range ($tmp), record ignored";
+                       return;
+               }
+               $h{Humidity_Out} = $tmp;
+               $tmp = int(unpack("C", substr $blk,11,1)+0);
+               if ($tmp > 100) {
+                       dbg "LOOP Inside Humidity out of range ($tmp), record ignored";
+                       return;
+               }
+               $h{Humidity_In}  = $tmp;
+               
 
                $tmp = unpack("C", substr $blk,43,1)+0;
                $h{UV} = $tmp unless $tmp >= 255;
@@ -354,7 +370,7 @@ sub process
                $ld->{Temp_Out_Max} = $temp if $temp > $ld->{Temp_Out_Max};
                $ld->{Temp_Out_Min} = $temp if $temp < $ld->{Temp_Out_Min};
 
-               if ($ts >= $ld->{last_hour} + 3600) {
+               if ($ts >= $ld->{last_hour} + 1800) {
                        $h{Pressure_Trend}    = unpack("C", substr $blk,3,1);
                        $h{Pressure_Trend_txt} = $bar_trend{$h{Pressure_Trend}};
                        $h{Batt_TX_OK}  = (unpack("C", substr $blk,86,1)+0) ^ 1;
@@ -384,7 +400,7 @@ sub process
 
                        $s = genstr($ts, 'h', \%h);
                        
-                       $ld->{last_hour} = int($ts/3600)*3600;
+                       $ld->{last_hour} = int($ts/1800)*1800;
                        $ld->{last_min} = int($ts/60)*60;
                        @{$ld->{wind_hour}} = ();
                        @{$ld->{wind_min}} = ();