11 our $dlog; # the day log
12 our $loop; # the Davis VP2 driver
14 helper debug_start => sub {
22 dbg "*** starting $0";
26 helper debug_stop => sub {
32 helper loop_start => sub {
37 helper loop_stop => sub {
41 helper dlog_start => sub {
42 $dlog = SMGLog->new("day");
46 helper dlog_stop => sub {
56 # WebSocket weather service
57 websocket '/weather_data' => sub {
61 $c->app->log->debug('WebSocket opened.');
62 dbg 'WebSocket opened' if isdbg 'chan';
64 # Increase inactivity timeout for connection a bit
65 $c->inactivity_timeout(60*60);
71 dbg "websocket: $msg" if isdbg 'chan';
75 dbg "websocket: $msg" if isdbg 'chan';
80 $c->on(finish => sub {
81 my ($c, $code, $reason) = @_;
82 $c->app->log->debug("WebSocket closed with status $code.");
83 dbg 'WebSocket closed with status $code' if isdbg 'chan';
107 <head><title>DWeather</title></head>
111 if ("WebSocket" in window) {
112 ws = new WebSocket('<%= url_for('index')->to_abs %>');
113 //ws = new WebSocket();
115 if(typeof(ws) !== 'undefined') {
116 ws.onmessage = function (event) {
117 document.body.innerHTML += JSON.parse(event.data).test;
119 ws.onopen = function (event) {
120 ws.send(JSON.stringify({weather: 'WebSocket support works! ♥'}));
124 document.body.innerHTML += 'Browser does not support WebSockets.';
127 var ws = new WebSocket('<%= url_for('weather')->to_abs %>');
130 ws.onmessage = function(event) {
131 document.body.innerHTML += event.data + '<br/>';