From ff9c8c8ded1b0ef402d75d968c07c15d6c4cbe1a Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Sat, 18 Apr 2015 01:15:51 +0100 Subject: [PATCH] Now with a graph!! --- SMGLog.pm | 1 + loop.pl | 155 ++++------------------ templates/index.html.ep | 278 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 302 insertions(+), 132 deletions(-) create mode 100644 templates/index.html.ep diff --git a/SMGLog.pm b/SMGLog.pm index e826a53..9adf77a 100644 --- a/SMGLog.pm +++ b/SMGLog.pm @@ -53,6 +53,7 @@ sub new my $dir = "$path/$prefix"; $ref->{prefix} = $dir; $ref->{suffix} = $suffix || 'log'; + $ref->{dayno} = int (time / 86400); # make sure the directory exists mkpath($dir, 0, 0777) unless -d $dir; diff --git a/loop.pl b/loop.pl index bc9bf7f..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}; }); }; @@ -492,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}|; } @@ -709,136 +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: -
-
-
-
-
-
-
- - - - - - +} diff --git a/templates/index.html.ep b/templates/index.html.ep new file mode 100644 index 0000000..8aeae1d --- /dev/null +++ b/templates/index.html.ep @@ -0,0 +1,278 @@ +% 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:
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + + + + + + + + + + -- 2.34.1