From: Dirk Koopman Date: Tue, 20 Jan 2015 20:24:49 +0000 (+0000) Subject: add some range checking... X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=79f2d3bd97c7a231531c3ebc562992bf3a647e16;p=dweather.git add some range checking... --- diff --git a/loop.pl b/loop.pl index ca85bbd..30bea05 100755 --- 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}} = ();