X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=loop.pl;h=b0e430055b5cebe676ea338e091255938619502a;hb=ff9c8c8ded1b0ef402d75d968c07c15d6c4cbe1a;hp=1fb8998e2361a4a1f8a3f43c7925648fb4c61586;hpb=636f61639c1bfc1ad597c3f2f9f025a84b0405cd;p=dweather.git diff --git a/loop.pl b/loop.pl index 1fb8998..b0e4300 100755 --- a/loop.pl +++ b/loop.pl @@ -108,6 +108,12 @@ 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}; + + # send the last 24 hour's worth of data to the graph + my $lg = SMGLog->new('day'); + my $tnow = time; + my $dayno = int($tnow/86400); + send_history($c, $lg, $tnow, $_) for ($dayno-1, $dayno); # disable timeout $c->inactivity_timeout(3615); @@ -128,7 +134,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}; }); }; @@ -157,6 +163,8 @@ dbg "after app start"; write_ld(); $dataf->close if $dataf; +undef $dataf; + # move all the files along one cycle_loop_data_files(); @@ -490,7 +498,7 @@ sub genstr my $h = shift; my $j = $json->encode($h); - my $tm = clocktime($ts, 1); + my $tm = clocktime($ts, $let eq 'r' ? 1 : 0); return qq|{"tm":"$tm","t":$ts,"$let":$j}|; } @@ -534,7 +542,7 @@ sub gen_hash_diff my $count; while (my ($k, $v) = each %$now) { - if ($last->{$k} ne $now->{$k}) { + if (!exists $last->{$k} || $last->{$k} ne $now->{$k}) { $o{$k} = $v; ++$count; } @@ -698,6 +706,7 @@ sub write_ld sub cycle_loop_data_files { $dataf->close if $dataf; + undef $dataf; rename "$datafn.oooo", "$datafn.ooooo"; rename "$datafn.ooo", "$datafn.oooo"; @@ -706,118 +715,21 @@ 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: -
-
-
-
-
- - - - - - +}