Send wind even if it hasn't changed
[dweather.git] / loop.pl
diff --git a/loop.pl b/loop.pl
index 02a463a7d3f1569eda6f6065b4a6cf4e1007e2ad..e627dde79127b8a86f3f66a2cec460a97e6e46dc 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -355,7 +355,7 @@ sub process
 
                $temp  = nearest(0.1, f2c(unpack("s", substr $blk,12,2) / 10));
                $h{Temp_Out}  = $temp;
-               if ($temp > 75 || $temp < -75) {
+               if ($temp > 60 || $temp < -60) {
                        dbg "LOOP Temperature out of range ($temp), record ignored";
                        return;
                }
@@ -425,7 +425,8 @@ sub process
                my $cycledata;
                
                if ($dayno > $ld->{last_day}) {
-                       $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $ld->{Wind_Max} = $temp;
+                       $ld->{Wind_Max} = $wind->{w};
+                       $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $temp;
                        $ld->{Temp_Out_Max_T} = $ld->{Temp_Out_Min_T} = $ld->{Wind_Max_T} = clocktime($ts, 0);
                        $ld->{last_day} = $dayno;
                        ++$writeld;
@@ -448,6 +449,7 @@ sub process
                        ++$writeld;
                }
 
+
                if ($ts >= $ld->{last_hour} + 1800) {
                        $h{Pressure_Trend}    = unpack("C", substr $blk,3,1);
                        $h{Pressure_Trend_txt} = $bar_trend{$h{Pressure_Trend}};
@@ -509,6 +511,9 @@ sub process
                                $h{Wind_1m} = nearest(0.1, $a->{w});
                                $h{Dir_1m} = nearest(1, $a->{d});
                                ($h{Rain_1m}, $h{Rain_1h}, $h{Rain_24h}) = calc_rain($rain);
+
+                               my $wkph = $a->{w} * 3.6;
+                               $h{WindChill} = nearest(0.1, $a->{w} >= 1.2 ? 13.12 + 0.6215 * $temp - 11.37 * $wkph ** 0.16 + 0.3965 * $temp * $wkph ** 0.16 : $temp); 
                        }
                        $ld->{last_rain_min} = $rain;
                        $h{Temp_Out_Max} = $ld->{Temp_Out_Max};
@@ -530,18 +535,13 @@ sub process
 
                } else {
                        my $o = gen_hash_diff($ld->{last_h}, \%h);
-                       if ($o) {
-                               $o->{Dir} ||= $h{Dir};
-                               $o->{Wind} ||= $h{Wind};
-                               $o->{Dir} += 0;
-                               $o->{Wind} += 0;
-                               $s = genstr($ts, 'r', $o);
-                               push @last10minsr, $s;
-                               shift @last10minsr while @last10minsr > ($windmins * $updatepermin);
-                       }
-                       else {
-                               dbg "loop rec not changed" if isdbg 'chan';
-                       }
+                       $o ||= {};
+                       # we always send wind even if it hasn't changed in order to update the wind rose.
+                       $o->{Dir} ||= ($h{Dir} + 0);
+                       $o->{Wind} ||= ($h{Wind} + 0);
+                       $s = genstr($ts, 'r', $o);
+                       push @last10minsr, $s;
+                       shift @last10minsr while @last10minsr > ($windmins * $updatepermin);
                        output_str($s, 0) if $s;
                }
                $ld->{last_h} = \%h;