X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=loop.pl;h=2e9549120f84faee71707dd079360d97d9bd9e59;hb=1b7ccfa8837f5ec3fb2c43741b85fa4658c7b1b9;hp=71464fd208d81390b2fa588a348855c484adaf83;hpb=729468e0480bc5a382f61b29e0c4ae27866536d4;p=dweather.git diff --git a/loop.pl b/loop.pl index 71464fd..2e95491 100755 --- a/loop.pl +++ b/loop.pl @@ -13,6 +13,8 @@ use JSON; use Debug; use SMGLog; use Math::Round qw(nearest); +use File::Copy; +use Data::Random qw(rand_chars); use constant pi => 3.14159265358979; @@ -143,6 +145,8 @@ dbg '***'; dbg "*** starting $0"; dbg '***'; +read_ld(); + our $dlog = SMGLog->new("day"); dbg "before next tick"; Mojo::IOLoop->next_tick(sub { loop() }); @@ -153,6 +157,9 @@ dbg "after app start"; write_ld(); close $dataf if $dataf; +# move all the files along one +cycle_loop_data_files(); + dbg '***'; dbg "*** ending $0"; dbg '***'; @@ -163,12 +170,6 @@ exit 0; sub loop { - - open $dataf, "+>>", $datafn or die "cannot open $datafn $!"; - $dataf->autoflush(1); - - read_ld(); - dbg "last_min: " . scalar gmtime($ld->{last_min}); dbg "last_hour: " . scalar gmtime($ld->{last_hour}); @@ -375,6 +376,8 @@ sub process if ($dayno > $ld->{last_day}) { $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $temp; $ld->{last_day} = $dayno; + write_ld(); + cycle_loop_data_files(); } $ld->{Temp_Out_Max} = $temp if $temp > $ld->{Temp_Out_Max}; $ld->{Temp_Out_Min} = $temp if $temp < $ld->{Temp_Out_Min}; @@ -416,6 +419,7 @@ sub process @{$ld->{wind_hour}} = (); @{$ld->{wind_min}} = (); + output_str($s, 1) if $s; write_ld(); } elsif ($ts >= $ld->{last_min} + 60) { @@ -443,6 +447,7 @@ sub process $ld->{last_min} = int($ts/60)*60; @{$ld->{wind_min}} = (); + output_str($s, 1) if $s; write_ld(); } else { @@ -453,8 +458,8 @@ sub process else { dbg "loop rec not changed" if isdbg 'chan'; } + output_str($s, 0) if $s; } - output_str($s) if $s; $ld->{last_h} = \%h; ++$loop_count; } else { @@ -479,9 +484,11 @@ sub genstr sub output_str { my $s = shift; + my $logit = shift; + dbg $s; # say $s; - $dlog->writenow($s); + $dlog->writenow($s) if $logit; foreach my $ws (keys $WS) { my $tx = $WS->{$ws}; if ($tx) { @@ -618,7 +625,10 @@ sub calc_rain sub read_ld { - return unless $dataf; + unless ($dataf) { + open $dataf, "+>>", $datafn or die "cannot open $datafn $!"; + $dataf->autoflush(1); + } seek $dataf, 0, 0; my $s = <$dataf>; @@ -645,8 +655,11 @@ sub read_ld sub write_ld { - return unless $dataf; - + unless ($dataf) { + open $dataf, "+>>", $datafn or die "cannot open $datafn $!"; + $dataf->autoflush(1); + } + seek $dataf, 0, 0; truncate $dataf, 0; $ld->{ts} = time; @@ -655,6 +668,16 @@ sub write_ld print $dataf "$s\n"; } +sub cycle_loop_data_files +{ + close $dataf if $dataf; + + rename "$datafn.oooo", "$datafn.ooooo"; + rename "$datafn.ooo", "$datafn.oooo"; + rename "$datafn.oo", "$datafn.ooo"; + rename "$datafn.o", "$datafn.oo"; + copy $datafn, "$datafn.o"; +} __DATA__ @@ -662,21 +685,34 @@ __DATA__ % my $url = url_for 'weather'; - DWeather + + DWeather + + + + + + + + + + + -

DWeather

+

High View Weather

+ +
+


- +
+ -
Time: +Sunrise: +Sunset: +Console Volts: +TX Battery OK: +
Pressure: +Trend: +
Temperature in: Humidity: +
Temperature out: Min: Max: Humidity: Dew Point: +
Wind Direction: -Minute: +Minute Avg: Speed: -Minute: +Minute Avg: +
Rain Hour: +Rain 30mins: Day: 24hrs: Month: Year:
- +
+
+
+
+ + + + +