dbg "*** starting $0";
dbg '***';
+read_ld();
+
our $dlog = SMGLog->new("day");
dbg "before next tick";
Mojo::IOLoop->next_tick(sub { loop() });
sub loop
{
- read_ld();
-
dbg "last_min: " . scalar gmtime($ld->{last_min});
dbg "last_hour: " . scalar gmtime($ld->{last_hour});
@{$ld->{wind_hour}} = ();
@{$ld->{wind_min}} = ();
+ output_str($s, 1) if $s;
write_ld();
} elsif ($ts >= $ld->{last_min} + 60) {
$ld->{last_min} = int($ts/60)*60;
@{$ld->{wind_min}} = ();
+ output_str($s, 1) if $s;
write_ld();
} else {
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 {
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) {
<script>
var ws;
- function process(key,value) {
+ function process(key,value) {
var d = document.getElementById(key);
if (d !== null) {
d.innerHTML = value;
}
}
-
- function traverse(o) {
+
+ function traverse(o) {
console.log(o);
for (var i in o) {
process(i, o[i]);
}
}
}
-
-
- ws = new WebSocket('<%= $url->to_abs %>');
- document.body.innerHTML += '<center>ws connecting to: <%= $url->to_abs %> type_of: ' + typeof(ws) + '</center><br>';
- if (typeof(ws) === 'object') {
- ws.onmessage = function (event) {
- var js = JSON.parse(event.data);
- if (js !== null && typeof(js) === 'object') {
- traverse(js);
+
+ window.onload = function() {
+
+ ws = new WebSocket('<%= $url->to_abs %>');
+
+ if (typeof(ws) === 'object') {
+ ws.onmessage = function (event) {
+ var js = JSON.parse(event.data);
+ if (js !== null && typeof(js) === 'object') {
+ traverse(js);
+ }
+ };
+ ws.onopen = function (event) {
+ document.getElementById("wsconnect").innerHTML = 'ws connected to: <%= $url->to_abs %>';
+ ws.send('WebSocket support works! ♥');
+ };
+ ws.onclose = function(event) {
+ document.getElementById("wsconnect").innerHTML = 'ws disconnected, refresh to restart';
}
- };
- ws.onopen = function (event) {
- ws.send('WebSocket support works! ♥');
- };
- } else {
- document.body.innerHTML += 'Webserver only works with Websocket aware browsers';
- }
-
+ } else {
+ document.body.innerHTML += 'Webserver only works with Websocket aware browsers';
+ }
+ }
</script>
<div id="container">
<th>Month:<td> <span id="Rain_Month"> </span>
<th>Year:<td> <span id="Rain_Year"> </span>
</table>
+<br>
+<div id="wsconnect" align="center"> </div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->