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 = <%= $main::histdays %>;
26 var windrose_mins = <%= $main::windmins %>;
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);
75 if ("r" in js || "m" in js) {
82 fill_windrose(rr, windrose_mins * $updatespermin);
90 ws.onopen = function (event) {
91 document.getElementById("wsconnect").innerHTML = 'ws connected to: <%= $url->to_abs %>';
92 ws.send('WebSocket support works!');
94 ws.onclose = function(event) {
95 document.getElementById("wsconnect").innerHTML = 'ws disconnected, refresh to restart';
99 document.body.innerHTML += 'Webserver only works with Websocket aware browsers';
103 function start_daychart() {
104 daychart = new Highcharts.Chart({
106 renderTo: 'daychart',
110 text: 'Five Day Chart'
117 yAxis: [{ // Primary yAxis
121 color: Highcharts.getOptions().colors[2]
127 color: Highcharts.getOptions().colors[2]
132 }, { // Secondary yAxis
137 color: Highcharts.getOptions().colors[0]
141 format: '{value} mm',
143 color: Highcharts.getOptions().colors[0]
147 }, { // Tertiary yAxis
150 text: 'Sea-Level Pressure',
152 color: Highcharts.getOptions().colors[1]
156 format: '{value} mb',
158 color: Highcharts.getOptions().colors[1]
170 verticalAlign: 'top',
173 backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
188 // format: '{point.y:.1f}', // one decimal
194 for (@main::last5daysh) {
195 my $r = $main::json->decode($_);
196 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r && exists $r->{t} && exists $r->{h}->{Rain_1h};
198 chop $s if length $s;
206 name: 'Sea-Level Pressure',
211 for (@main::last5daysh) {
212 my $r = $main::json->decode($_);
213 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r && exists $r->{t} && exists $r->{h}->{Pressure};
215 chop $s if length $s;
221 dashStyle: 'shortdot',
231 for (@main::last5daysh) {
232 my $r = $main::json->decode($_);
233 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Temp_Out};
235 chop $s if length $s;
245 function start_windrose() {
248 Highcharts.createElement('link', {
249 href: '//fonts.googleapis.com/css?family=Dosis:400,600',
252 }, null, document.getElementsByTagName('head')[0]);
255 colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
256 "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
258 backgroundColor: null,
260 fontFamily: "Dosis, sans-serif"
267 textTransform: 'uppercase'
272 backgroundColor: 'rgba(219,219,216,0.8)',
290 minorTickInterval: 'auto',
293 textTransform: 'uppercase'
310 background2: '#F0F0EA'
315 Highcharts.setOptions(Highcharts.theme);
317 windrose = new Highcharts.Chart({
337 formatter: function () {
338 return this.value + '°';
372 for (@main::last10minsr) {
373 my $r = $main::json->decode($_);
375 $r->{r}->{Dir} ||= $d;
376 $r->{r}->{Wind} ||= $w;
377 $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "],";
379 $w = $r->{r}->{Wind};
382 chop $s if length $s;
389 function start_windspeed() {
390 windspeed = new Highcharts.Chart({
393 renderTo: 'windspeed',
394 plotBackgroundColor: null,
395 plotBackgroundImage: null,
409 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
419 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
428 // default background
430 backgroundColor: '#DDD',
442 minorTickInterval: 'auto',
445 minorTickPosition: 'inside',
446 minorTickColor: '#666',
448 tickPixelInterval: 30,
450 tickPosition: 'inside',
463 color: '#55BF3B' // green
467 color: '#DDDF0D' // yellow
471 color: '#DF5353' // red
492 function start_winddir() {
493 winddir = new Highcharts.Chart({
497 plotBackgroundColor: null,
498 plotBackgroundImage: null,
504 text: 'Wind Direction'
512 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
522 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
531 // default background
533 backgroundColor: '#DDD',
545 minorTickInterval: 'auto',
548 minorTickPosition: 'inside',
549 minorTickColor: '#666',
551 tickPixelInterval: 15,
553 tickPosition: 'inside',
576 valueSuffix: ' ° deg'
582 function fill_daychart(js, days) {
583 var rainfall = daychart.series[0].data.length > (days * 48);
584 var pressure = daychart.series[1].data.length > (days * 48);
585 var temp = daychart.series[2].data.length > (days * 48);
589 var ra = [t, hr.Rain_1h];
590 var pr = [t, hr.Pressure];
591 var te = [t, hr.Temp_Out];
593 // do_debug(js.tm + " " + t + " " + te + "<br>");
594 daychart.series[0].addPoint(ra, true, rainfall);
595 daychart.series[1].addPoint(pr, true, pressure);
596 daychart.series[2].addPoint(te, true, temp);
601 function fill_windrose(rr, points) {
602 var p = windrose.series[0].data.length > points;
603 var v = [rr.Dir, (rr.Wind*conv)];
604 windrose.series[0].addPoint(v, true, p);
607 function fill_windspeed(rr) {
608 var point = windspeed.series[0].points[0];
609 point.update(Math.round(rr.Wind*conv));
612 function fill_winddir(rr) {
613 var point = winddir.series[0].points[0];
614 point.update(rr.Dir);
617 window.onload = function() {
623 window.setInterval(function() {
632 <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
636 <table border="0" align="center">
638 <td id="windrose" style="min-width: 350px; max-width: 400px; height: 330px; margin: 0 auto"> </td>
639 <td id="windspeed" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
640 <td id="winddir" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
646 <div id="start-template">
648 <table border=1 width=80% align="center">
650 <th>Time:</th><td><span id="tm"> </span></td>
651 <th>Sunrise:</th><td><span id="Sunrise"> </span></td>
652 <th>Sunset:</th><td><span id="Sunset"> </span></td>
653 <th>Console Volts:</th><td><span id="Batt_Console"> </span></td>
654 <th>TX Battery OK:</th><td><span id="Batt_TX_OK"> </span></td>
657 <th>Pressure:</th><td><span id="Pressure"> </span></td>
658 <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
661 <th>Temperature in:</th><td> <span id="Temp_In"> </span></td>
662 <th>Humidity:</th><td> <span id="Humidity_In"> </span></td>
665 <th>Min:</th><td> <span id="Temp_Out_Min"> </span> @ <span id="Temp_Out_Min_T"> </span></td>
666 <th>Max:</th><td> <span id="Temp_Out_Max"> </span> @ <span id="Temp_Out_Max_T"> </span></td>
667 <th>Humidity:</th><td> <span id="Humidity_Out"> </span></td>
668 <th>Dew Point:</th><td> <span id="Dew_Point"> </span></td>
671 <th>Wind Dir Minute Avg:</th><td> <span id="Dir_1m"> </span></td>
672 <th>Wind Speed Minute Avg:</th><td> <span id="Wind_1m"> </span></td>
675 <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span></td>
676 <th>Day:</th><td> <span id="Rain_Day"> </span></td>
677 <th>24hrs:</th><td> <span id="Rain_24h"> </span></td>
678 <th>Month:</th><td> <span id="Rain_Month"> </span></td>
679 <th>Year:</th><td> <span id="Rain_Year"> </span></td>
686 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
687 <script src="js/jquery.min.js"></script>
688 <!-- Latest compiled and minified JavaScript -->
689 <script src="js/bootstrap.min.js"></script>
690 <!-- High Chart stuff -->
691 <script src="js/highcharts.js"></script>
692 <script src="js/highcharts-more.js"></script>
693 <script src="js/modules/exporting.js"></script>