X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=loop.pl;h=e287ce5913b0370d0aa32345ac6348b42b343541;hb=b5935e862dc6dd1a6b6154905bac6db8836132d6;hp=bb28f1843e7372b2164aa90c7427ab2ae32b3b2f;hpb=feceb0bda28cea09e43b9497e38510ef404d5c4a;p=dweather.git diff --git a/loop.pl b/loop.pl index bb28f18..e287ce5 100755 --- a/loop.pl +++ b/loop.pl @@ -40,6 +40,11 @@ our $json = JSON->new->canonical(1); our $WS = {}; # websocket connections our $ld = {}; +our @last10minsr = (); +our @last5daysh = (); +our $windmins = 2; # no of minutes of wind data for the windrose +our $histdays = 5; # no of days of (half)hour data to search for main graph +our $updatepermin = 60 / 2.5; # no of updates per minute our $loop_count; # how many LOOPs we have done, used as start indicator @@ -108,7 +113,7 @@ websocket '/weather' => sub { # send historical data $c->send($ld->{lasthour_h}) if exists $ld->{lasthour_h}; $c->send($ld->{lastmin_h}) if exists $ld->{lastmin_h}; - + # disable timeout $c->inactivity_timeout(3615); @@ -128,7 +133,7 @@ websocket '/weather' => sub { $c->on(finish => sub { my ($c, $code, $reason) = @_; app->log->debug("WebSocket closed with status $code."); - dbg 'webwocket closed with status $code' if isdbg 'chan'; + dbg "websocket closed with status $code" if isdbg 'chan'; delete $WS->{$tx}; }); }; @@ -147,11 +152,20 @@ dbg "*** starting $0"; dbg '***'; read_ld(); - + +my $tnow = time; +my $dayno = int ($tnow/86400); +for (my $i = 0-$histdays; $i < 0; ++$i ) { + push @last5daysh, grab_history(SMGLog->new("day"), "h", $tnow-(86400*$histdays), $dayno+$i+1); +} +@last10minsr = map {my ($t, $js) = split(/\s/, $_, 2); $js} grab_history(SMGLog->new("debug"), "r", $tnow-(60*$windmins), $dayno); +dbg sprintf("last5days = %d last10mins = %d", scalar @last5daysh, scalar @last10minsr); + our $dlog = SMGLog->new("day"); dbg "before next tick"; Mojo::IOLoop->next_tick(sub { loop() }); dbg "before app start"; +app->secrets([qw(Here's something that's really seakrett)]); app->start; dbg "after app start"; @@ -434,7 +448,11 @@ sub process @{$ld->{wind_hour}} = (); @{$ld->{wind_min}} = (); - output_str($s, 1) if $s; + if ($s) { + output_str($s, 1); + push @last5daysh, $s; + shift @last5daysh if @last5daysh > 5*24; + } write_ld(); } elsif ($ts >= $ld->{last_min} + 60) { @@ -470,7 +488,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'; @@ -709,118 +733,23 @@ sub cycle_loop_data_files copy $datafn, "$datafn.o"; } -__DATA__ - -@@ index.html.ep -% my $url = url_for 'weather'; - - - - 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 Avg: - Speed: - Minute Avg: - -
Rain 30mins: - Day: - 24hrs: - Month: - Year: -
-
-
-
-
- - - - - - + return @out; +}