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 %>;
29 var updatespermin = <%= $main::updatepermin %>;
33 function do_debug(text) {
34 document.getElementById("do_debug").innerHTML = text;
37 function update_h(key, value) {
41 function fill_html(key,value) {
42 var d = document.getElementById(key);
48 function traverse(o, func) {
51 if (o[i] !== null && typeof(o[i])==="object") {
64 ws = new WebSocket('<%= $url->to_abs %>');
66 if (typeof(ws) !== null) {
67 ws.onmessage = function (event) {
68 var js = JSON.parse(event.data);
69 if (js !== null && typeof(js) === 'object') {
70 traverse(js, fill_html);
71 // traverse(js, update_h);
72 // document.getElementById("hh").innerHTML = JSON.stringify(h);
74 fill_daychart(js, daychart_days);
76 if ("r" in js || "m" in js) {
83 fill_windrose(rr, windrose_mins * updatespermin);
91 ws.onopen = function (event) {
92 document.getElementById("wsconnect").innerHTML = 'ws connected to: <%= $url->to_abs %>';
93 ws.send('WebSocket support works!');
95 ws.onclose = function(event) {
96 document.getElementById("wsconnect").innerHTML = 'ws disconnected, refresh to restart';
100 document.body.innerHTML += 'Webserver only works with Websocket aware browsers';
104 function start_daychart() {
105 daychart = new Highcharts.Chart({
107 renderTo: 'daychart',
111 text: 'Five Day Chart'
118 yAxis: [{ // Primary yAxis
133 }, { // Secondary yAxis
138 color: Highcharts.getOptions().colors[0]
142 format: '{value} mm',
144 color: Highcharts.getOptions().colors[0]
148 }, { // Tertiary yAxis
151 text: 'Sea-Level Pressure',
153 color: Highcharts.getOptions().colors[1]
157 format: '{value} mb',
159 color: Highcharts.getOptions().colors[1]
171 verticalAlign: 'top',
174 backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
189 // format: '{point.y:.1f}', // one decimal
195 for (@main::last5daysh) {
196 my $r = $main::json->decode($_);
197 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r && exists $r->{t} && exists $r->{h}->{Rain_1h};
199 chop $s if length $s;
207 name: 'Sea-Level Pressure',
212 for (@main::last5daysh) {
213 my $r = $main::json->decode($_);
214 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r && exists $r->{t} && exists $r->{h}->{Pressure};
216 chop $s if length $s;
222 dashStyle: 'shortdot',
233 for (@main::last5daysh) {
234 my $r = $main::json->decode($_);
235 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Temp_Out};
237 chop $s if length $s;
247 function start_windrose() {
250 Highcharts.createElement('link', {
251 href: '//fonts.googleapis.com/css?family=Dosis:400,600',
254 }, null, document.getElementsByTagName('head')[0]);
257 colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
258 "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
260 backgroundColor: null,
262 fontFamily: "Dosis, sans-serif"
269 textTransform: 'uppercase'
274 backgroundColor: 'rgba(219,219,216,0.8)',
292 minorTickInterval: 'auto',
295 textTransform: 'uppercase'
312 background2: '#F0F0EA'
317 Highcharts.setOptions(Highcharts.theme);
319 windrose = new Highcharts.Chart({
339 formatter: function () {
340 return this.value + '°';
374 for (@main::last10minsr) {
375 my $r = $main::json->decode($_);
377 $r->{r}->{Dir} ||= $d;
378 $r->{r}->{Wind} ||= $w;
379 $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "],";
381 $w = $r->{r}->{Wind};
384 chop $s if length $s;
391 function start_windspeed() {
392 windspeed = new Highcharts.Chart({
395 renderTo: 'windspeed',
396 plotBackgroundColor: null,
397 plotBackgroundImage: null,
411 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
421 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
430 // default background
432 backgroundColor: '#DDD',
444 minorTickInterval: 'auto',
447 minorTickPosition: 'inside',
448 minorTickColor: '#666',
450 tickPixelInterval: 30,
452 tickPosition: 'inside',
465 color: '#55BF3B' // green
469 color: '#DDDF0D' // yellow
473 color: '#DF5353' // red
494 function start_winddir() {
495 winddir = new Highcharts.Chart({
499 plotBackgroundColor: null,
500 plotBackgroundImage: null,
506 text: 'Wind Direction'
514 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
524 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
533 // default background
535 backgroundColor: '#DDD',
547 minorTickInterval: 'auto',
550 minorTickPosition: 'inside',
551 minorTickColor: '#666',
553 tickPixelInterval: 15,
555 tickPosition: 'inside',
578 valueSuffix: ' ° deg'
584 function fill_daychart(js, days) {
585 var rainfall = daychart.series[0].data.length > (days * 48);
586 var pressure = daychart.series[1].data.length > (days * 48);
587 var temp = daychart.series[2].data.length > (days * 48);
591 var ra = [t, hr.Rain_1h];
592 var pr = [t, hr.Pressure];
593 var te = [t, hr.Temp_Out];
595 // do_debug(js.tm + " " + t + " " + te + "<br>");
596 daychart.series[0].addPoint(ra, true, rainfall);
597 daychart.series[1].addPoint(pr, true, pressure);
598 daychart.series[2].addPoint(te, true, temp);
603 function fill_windrose(rr, points) {
604 var p = windrose.series[0].data.length > points;
605 var v = [rr.Dir, (rr.Wind*conv)];
606 windrose.series[0].addPoint(v, true, p);
609 function fill_windspeed(rr) {
610 var point = windspeed.series[0].points[0];
611 point.update(Math.round(rr.Wind*conv));
614 function fill_winddir(rr) {
615 var point = winddir.series[0].points[0];
616 point.update(rr.Dir);
619 window.onload = function() {
625 window.setInterval(function() {
634 <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
638 <table border="0" align="center">
640 <td id="windrose" style="min-width: 350px; max-width: 400px; height: 330px; margin: 0 auto"> </td>
641 <td id="windspeed" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
642 <td id="winddir" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
648 <div id="start-template">
650 <table class="table">
652 <th>Time:</th><td><span id="tm"> </span></td>
653 <th>Sunrise:</th><td><span id="Sunrise"> </span></td>
654 <th>Sunset:</th><td><span id="Sunset"> </span></td>
655 <th>Console Volts:</th><td><span id="Batt_Console"> </span></td>
656 <th>TX Battery OK:</th><td><span id="Batt_TX_OK"> </span></td>
659 <th>Pressure:</th><td><span id="Pressure"> </span></td>
660 <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
663 <th>Temperature in:</th><td> <span id="Temp_In"> </span></td>
664 <th>Humidity:</th><td> <span id="Humidity_In"> </span></td>
666 <tr><th>Temperature out:</th><td> <span id="Temp_Out"> </span></td>
667 <th>Min:</th><td> <span id="Temp_Out_Min"> </span> @ <span id="Temp_Out_Min_T"> </span></td>
668 <th>Max:</th><td> <span id="Temp_Out_Max"> </span> @ <span id="Temp_Out_Max_T"> </span></td>
669 <th>Humidity:</th><td> <span id="Humidity_Out"> </span></td>
670 <th>Dew Point:</th><td> <span id="Dew_Point"> </span></td>
672 <tr><th>Wind:</th><td><span id="Wind"> </span> mph @ <span id="Dir"> </span> deg</td>
673 <th>Wind Dir Minute Avg:</th><td> <span id="Dir_1m"> </span></td>
674 <th>Wind Speed Minute Avg:</th><td> <span id="Wind_1m"> </span></td>
677 <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span></td>
678 <th>Day:</th><td> <span id="Rain_Day"> </span></td>
679 <th>24hrs:</th><td> <span id="Rain_24h"> </span></td>
680 <th>Month:</th><td> <span id="Rain_Month"> </span></td>
681 <th>Year:</th><td> <span id="Rain_Year"> </span></td>
688 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
689 <script src="js/jquery.min.js"></script>
690 <!-- Latest compiled and minified JavaScript -->
691 <script src="js/bootstrap.min.js"></script>
692 <!-- High Chart stuff -->
693 <script src="js/highcharts.js"></script>
694 <script src="js/highcharts-more.js"></script>
695 <script src="js/modules/exporting.js"></script>