]> dxcluster.org Git - dweather.git/commitdiff
add min/max outside temperature
authorDirk Koopman <djk@tobit.co.uk>
Sat, 17 Jan 2015 19:56:10 +0000 (19:56 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 17 Jan 2015 19:56:10 +0000 (19:56 +0000)
loop.pl

diff --git a/loop.pl b/loop.pl
index 21c436da257cd8614a0c7c46d0e0a907b428828b..ca85bbd9671ddfc59da24fc7961d7fd9ba819348 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -280,6 +280,7 @@ sub process
        }
 
        my $tmp;
+       my $temp;
        my $rain;
        my %h;
 
@@ -294,8 +295,8 @@ sub process
                $tmp = unpack("s", substr $blk,9,2) / 10;
                $h{Temp_In} = nearest(0.1, f2c($tmp));
 
-               $tmp  = unpack("s", substr $blk,12,2) / 10;
-               $h{Temp_Out}  = nearest(0.1, f2c($tmp));
+               $temp  = nearest(0.1, f2c(unpack("s", substr $blk,12,2) / 10));
+               $h{Temp_Out}  = $temp;
 
                $tmp = unpack("C", substr $blk,14,1);
                $h{Wind} = nearest(0.1, mph2mps($tmp));
@@ -345,6 +346,14 @@ sub process
 
                my $ts = time;
                my $s;
+               my $dayno = int($ts/86400);
+               if ($dayno > $ld->{last_day}) {
+                       $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $temp;
+                       $ld->{last_day} = $dayno;
+               }
+               $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) {
                        $h{Pressure_Trend}    = unpack("C", substr $blk,3,1);
                        $h{Pressure_Trend_txt} = $bar_trend{$h{Pressure_Trend}};
@@ -356,6 +365,8 @@ sub process
                        $h{Sunrise}  =~ s/(\d{2})(\d{2})/$1:$2/;
                        $h{Sunset}   = sprintf( "%04d", unpack("S", substr $blk,93,2) );
                        $h{Sunset}  =~ s/(\d{2})(\d{2})/$1:$2/;
+                       $h{Temp_Out_Max} = $ld->{Temp_Out_Max};
+                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min};
 
                        if ($loop_count) {      # i.e not the first
                                my $a = wind_average(scalar @{$ld->{wind_hour}} ? @{$ld->{wind_hour}} : {w => $h{Wind}, d => $h{Dir}});
@@ -395,6 +406,9 @@ sub process
                        }
                        $ld->{last_rain_min} = $rain;
 
+                       $h{Temp_Out_Max} = $ld->{Temp_Out_Max};
+                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min};
+
                        $s = genstr($ts, 'm', \%h);
                        
                        $ld->{last_min} = int($ts/60)*60;
@@ -554,7 +568,7 @@ sub calc_rain
        $ld->{rain24} ||= [];
        
        my $Rain_1h = nearest(0.1, $rain >= $ld->{last_rain_hour} ? $rain - $ld->{last_rain_hour} : $rain); # this is the rate for this hour, so far
-       my $rm = $rain >= $ld->{last_rain_min} ? $rain - $ld->{last_rain_min} : $rain;
+       my $rm = nearest(0.1, $rain >= $ld->{last_rain_min} ? $rain - $ld->{last_rain_min} : $rain);
        my $Rain_1m = nearest(0.1, $rm);
        push @{$ld->{rain24}}, $Rain_1m;
        $ld->{rain_24} += $rm;