1 % my $url = url_for 'weather';
6 <title>DWeather</title>
8 <meta http-equiv="X-UA-Compatible" content="IE=edge">
9 <meta name="viewport" content="width=device-width, initial-scale=1">
11 <!-- Latest compiled and minified CSS -->
12 <link rel="stylesheet" href="css/bootstrap.min.css">
14 <!-- Optional theme -->
15 <link rel="stylesheet" href="css/bootstrap-theme.min.css">
19 <center><h1>High View Weather</h1></center>
24 var daychart_days = 5;
26 var windrose_mins = 10;
32 function do_debug(text) {
33 document.getElementById("do_debug").innerHTML = text;
36 function update_h(key, value) {
40 function fill_html(key,value) {
41 var d = document.getElementById(key);
47 function traverse(o, func) {
50 if (o[i] !== null && typeof(o[i])==="object") {
63 ws = new WebSocket('<%= $url->to_abs %>');
65 if (typeof(ws) !== null) {
66 ws.onmessage = function (event) {
67 var js = JSON.parse(event.data);
68 if (js !== null && typeof(js) === 'object') {
69 traverse(js, fill_html);
70 // traverse(js, update_h);
71 // document.getElementById("hh").innerHTML = JSON.stringify(h);
73 fill_daychart(js, daychart_days);
76 // if (js.t > lastt + 15) {
88 fill_windrose(js, windrose_mins * (60 / 2.5));
95 ws.onopen = function (event) {
96 document.getElementById("wsconnect").innerHTML = 'ws connected to: <%= $url->to_abs %>';
97 ws.send('WebSocket support works!');
99 ws.onclose = function(event) {
100 document.getElementById("wsconnect").innerHTML = 'ws disconnected, refresh to restart';
104 document.body.innerHTML += 'Webserver only works with Websocket aware browsers';
108 function start_daychart() {
109 daychart = new Highcharts.Chart({
111 renderTo: 'daychart',
115 text: 'Five Day Chart'
122 yAxis: [{ // Primary yAxis
126 color: Highcharts.getOptions().colors[2]
132 color: Highcharts.getOptions().colors[2]
137 }, { // Secondary yAxis
142 color: Highcharts.getOptions().colors[0]
146 format: '{value} mm',
148 color: Highcharts.getOptions().colors[0]
152 }, { // Tertiary yAxis
155 text: 'Sea-Level Pressure',
157 color: Highcharts.getOptions().colors[1]
161 format: '{value} mb',
163 color: Highcharts.getOptions().colors[1]
175 verticalAlign: 'top',
178 backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
186 for (@main::last5daysh) {
187 my $r = $main::json->decode($_);
188 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r;
190 chop $s if length $s;
198 name: 'Sea-Level Pressure',
203 for (@main::last5daysh) {
204 my $r = $main::json->decode($_);
205 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r;
207 chop $s if length $s;
213 dashStyle: 'shortdot',
223 for (@main::last5daysh) {
224 my $r = $main::json->decode($_);
225 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r;
227 chop $s if length $s;
237 function start_windrose() {
240 Highcharts.createElement('link', {
241 href: '//fonts.googleapis.com/css?family=Dosis:400,600',
244 }, null, document.getElementsByTagName('head')[0]);
247 colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
248 "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
250 backgroundColor: null,
252 fontFamily: "Dosis, sans-serif"
259 textTransform: 'uppercase'
264 backgroundColor: 'rgba(219,219,216,0.8)',
282 minorTickInterval: 'auto',
285 textTransform: 'uppercase'
302 background2: '#F0F0EA'
307 Highcharts.setOptions(Highcharts.theme);
309 windrose = new Highcharts.Chart({
329 formatter: function () {
330 return this.value + '°';
357 for (@main::last10minsr) {
358 my $r = $main::json->decode($_);
360 $r->{r}->{Dir} ||= $d;
361 $r->{r}->{Wind} ||= $w;
362 $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "]," if $r;
364 $w = $r->{r}->{Wind};
367 chop $s if length $s;
374 function start_windspeed() {
375 windspeed = new Highcharts.Chart({
378 renderTo: 'windspeed',
379 plotBackgroundColor: null,
380 plotBackgroundImage: null,
394 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
404 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
413 // default background
415 backgroundColor: '#DDD',
427 minorTickInterval: 'auto',
430 minorTickPosition: 'inside',
431 minorTickColor: '#666',
433 tickPixelInterval: 30,
435 tickPosition: 'inside',
448 color: '#55BF3B' // green
452 color: '#DDDF0D' // yellow
456 color: '#DF5353' // red
470 function start_winddir() {
471 winddir = new Highcharts.Chart({
475 plotBackgroundColor: null,
476 plotBackgroundImage: null,
482 text: 'Wind Direction'
490 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
500 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
509 // default background
511 backgroundColor: '#DDD',
523 minorTickInterval: 'auto',
526 minorTickPosition: 'inside',
527 minorTickColor: '#666',
529 tickPixelInterval: 15,
531 tickPosition: 'inside',
547 valueSuffix: ' ° deg'
553 function fill_daychart(js, days) {
554 var rainfall = daychart.series[0].data.length > (days * 48);
555 var pressure = daychart.series[1].data.length > (days * 48);
556 var temp = daychart.series[2].data.length > (days * 48);
560 var ra = [t, hr.Rain_1h];
561 var pr = [t, hr.Pressure];
562 var te = [t, hr.Temp_Out];
564 // do_debug(js.tm + " " + t + " " + te + "<br>");
565 daychart.series[0].addPoint(ra, true, rainfall);
566 daychart.series[1].addPoint(pr, true, pressure);
567 daychart.series[2].addPoint(te, true, temp);
572 function fill_windrose(js, points) {
573 var p = windrose.series[0].data.length > points;
575 windrose.series[0].addPoint([rr.Dir, Math.round(rr.Wind*conv)], true, p);
578 function fill_windspeed(js) {
580 var point = windspeed.series[0].points[0];
581 point.update(Math.round(rr.Wind*conv));
584 function fill_winddir(js) {
586 var point = winddir.series[0].points[0];
587 point.update(rr.Dir);
590 window.onload = function() {
596 window.setInterval(function() {
605 <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
609 <table border="0" align="center">
611 <td id="windrose" style="min-width: 350px; max-width: 400px; height: 330px; margin: 0 auto"> </td>
612 <td id="windspeed" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
613 <td id="winddir" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
619 <div id="start-template">
621 <table border=1 width=80% align="center">
623 <th>Time:</th><td><span id="tm"> </span></td>
624 <th>Sunrise:</th><td><span id="Sunrise"> </span></td>
625 <th>Sunset:</th><td><span id="Sunset"> </span></td>
626 <th>Console Volts:</th><td><span id="Batt_Console"> </span></td>
627 <th>TX Battery OK:</th><td><span id="Batt_TX_OK"> </span></td>
630 <th>Pressure:</th><td><span id="Pressure"> </span></td>
631 <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
634 <th>Temperature in:</th><td> <span id="Temp_In"> </span></td>
635 <th>Humidity:</th><td> <span id="Humidity_In"> </span></td>
638 <th>Min:</th><td> <span id="Temp_Out_Min"> </span> @ <span id="Temp_Out_Min_T"> </span></td>
639 <th>Max:</th><td> <span id="Temp_Out_Max"> </span> @ <span id="Temp_Out_Max_T"> </span></td>
640 <th>Humidity:</th><td> <span id="Humidity_Out"> </span></td>
641 <th>Dew Point:</th><td> <span id="Dew_Point"> </span></td>
644 <th>Wind Dir Minute Avg:</th><td> <span id="Dir_1m"> </span></td>
645 <th>Wind Speed Minute Avg:</th><td> <span id="Wind_1m"> </span></td>
648 <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span></td>
649 <th>Day:</th><td> <span id="Rain_Day"> </span></td>
650 <th>24hrs:</th><td> <span id="Rain_24h"> </span></td>
651 <th>Month:</th><td> <span id="Rain_Month"> </span></td>
652 <th>Year:</th><td> <span id="Rain_Year"> </span></td>
659 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
660 <script src="js/jquery.min.js"></script>
661 <!-- Latest compiled and minified JavaScript -->
662 <script src="js/bootstrap.min.js"></script>
663 <!-- High Chart stuff -->
664 <script src="js/highcharts.js"></script>
665 <script src="js/highcharts-more.js"></script>
666 <script src="js/modules/exporting.js"></script>