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]
163 }, { // Tertiary yAxis
188 verticalAlign: 'top',
191 backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
206 // format: '{point.y:.1f}', // one decimal
212 for (@main::last5daysh) {
213 my $r = $main::json->decode($_);
214 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r && exists $r->{t} && exists $r->{h}->{Rain_1h};
216 chop $s if length $s;
224 name: 'Sea-Level Pressure',
229 for (@main::last5daysh) {
230 my $r = $main::json->decode($_);
231 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r && exists $r->{t} && exists $r->{h}->{Pressure};
233 chop $s if length $s;
239 dashStyle: 'shortdot',
251 for (@main::last5daysh) {
252 my $r = $main::json->decode($_);
253 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Temp_Out};
255 chop $s if length $s;
268 for (@main::last5daysh) {
269 my $r = $main::json->decode($_);
270 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Humidity_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Humidity_Out};
272 chop $s if length $s;
278 dashStyle: 'shortdot',
286 function start_windrose() {
289 Highcharts.createElement('link', {
290 href: '//fonts.googleapis.com/css?family=Dosis:400,600',
293 }, null, document.getElementsByTagName('head')[0]);
296 colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
297 "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
299 backgroundColor: null,
301 fontFamily: "Dosis, sans-serif"
308 textTransform: 'uppercase'
313 backgroundColor: 'rgba(219,219,216,0.8)',
331 minorTickInterval: 'auto',
334 textTransform: 'uppercase'
351 background2: '#F0F0EA'
356 Highcharts.setOptions(Highcharts.theme);
358 windrose = new Highcharts.Chart({
378 formatter: function () {
379 return this.value + '°';
413 for (@main::last10minsr) {
414 my $r = $main::json->decode($_);
416 $r->{r}->{Dir} ||= $d;
417 $r->{r}->{Wind} ||= $w;
418 $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "],";
420 $w = $r->{r}->{Wind};
423 chop $s if length $s;
430 function start_windspeed() {
431 windspeed = new Highcharts.Chart({
434 renderTo: 'windspeed',
435 plotBackgroundColor: null,
436 plotBackgroundImage: null,
450 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
460 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
469 // default background
471 backgroundColor: '#DDD',
483 minorTickInterval: 'auto',
486 minorTickPosition: 'inside',
487 minorTickColor: '#666',
489 tickPixelInterval: 30,
491 tickPosition: 'inside',
504 color: '#55BF3B' // green
508 color: '#DDDF0D' // yellow
512 color: '#DF5353' // red
533 function start_winddir() {
534 winddir = new Highcharts.Chart({
538 plotBackgroundColor: null,
539 plotBackgroundImage: null,
545 text: 'Wind Direction'
553 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
563 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
572 // default background
574 backgroundColor: '#DDD',
586 minorTickInterval: 'auto',
589 minorTickPosition: 'inside',
590 minorTickColor: '#666',
592 tickPixelInterval: 15,
594 tickPosition: 'inside',
617 valueSuffix: ' ° deg'
623 function fill_daychart(js, days) {
624 var rainfall = daychart.series[0].data.length > (days * 48);
625 var pressure = daychart.series[1].data.length > (days * 48);
626 var temp = daychart.series[2].data.length > (days * 48);
630 var ra = [t, hr.Rain_1h];
631 var pr = [t, hr.Pressure];
632 var te = [t, hr.Temp_Out];
634 // do_debug(js.tm + " " + t + " " + te + "<br>");
635 daychart.series[0].addPoint(ra, true, rainfall);
636 daychart.series[1].addPoint(pr, true, pressure);
637 daychart.series[2].addPoint(te, true, temp);
642 function fill_windrose(rr, points) {
643 var p = windrose.series[0].data.length > points;
644 var v = [rr.Dir, (rr.Wind*conv)];
645 windrose.series[0].addPoint(v, true, p);
648 function fill_windspeed(rr) {
649 var point = windspeed.series[0].points[0];
650 point.update(Math.round(rr.Wind*conv));
653 function fill_winddir(rr) {
654 var point = winddir.series[0].points[0];
655 point.update(rr.Dir);
658 window.onload = function() {
664 window.setInterval(function() {
673 <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
677 <table border="0" align="center">
679 <td id="windrose" style="min-width: 350px; max-width: 400px; height: 330px; margin: 0 auto"> </td>
680 <td id="windspeed" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
681 <td id="winddir" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
687 <div id="start-template">
689 <table class="table">
691 <th>Time:</th><td><span id="tm"> </span></td>
692 <th>Sunrise:</th><td><span id="Sunrise"> </span></td>
693 <th>Sunset:</th><td><span id="Sunset"> </span></td>
694 <th>Console Volts:</th><td><span id="Batt_Console"> </span></td>
695 <th>TX Battery OK:</th><td><span id="Batt_TX_OK"> </span></td>
698 <th>Pressure:</th><td><span id="Pressure"> </span></td>
699 <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
702 <th>Temperature in:</th><td> <span id="Temp_In"> </span></td>
703 <th>Humidity:</th><td> <span id="Humidity_In"> </span></td>
705 <tr><th>Temperature out:</th><td> <span id="Temp_Out"> </span></td>
706 <th>Min:</th><td> <span id="Temp_Out_Min"> </span> @ <span id="Temp_Out_Min_T"> </span></td>
707 <th>Max:</th><td> <span id="Temp_Out_Max"> </span> @ <span id="Temp_Out_Max_T"> </span></td>
708 <th>Humidity:</th><td> <span id="Humidity_Out"> </span></td>
709 <th>Dew Point:</th><td> <span id="Dew_Point"> </span></td>
711 <tr><th>Wind:</th><td><span id="Wind"> </span> m/s @ <span id="Dir"> </span> deg</td>
712 <th>Wind Dir Minute Avg:</th><td> <span id="Dir_1m"> </span></td>
713 <th>Wind Speed Minute Avg:</th><td> <span id="Wind_1m"> </span></td>
716 <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span></td>
717 <th>Day:</th><td> <span id="Rain_Day"> </span></td>
718 <th>24hrs:</th><td> <span id="Rain_24h"> </span></td>
719 <th>Month:</th><td> <span id="Rain_Month"> </span></td>
720 <th>Year:</th><td> <span id="Rain_Year"> </span></td>
727 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
728 <script src="js/jquery.min.js"></script>
729 <!-- Latest compiled and minified JavaScript -->
730 <script src="js/bootstrap.min.js"></script>
731 <!-- High Chart stuff -->
732 <script src="js/highcharts.js"></script>
733 <script src="js/highcharts-more.js"></script>
734 <script src="js/modules/exporting.js"></script>