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);
627 var humidity = daychart.series[3].data.length > (days * 48);
631 var ra = [t, hr.Rain_1h];
632 var pr = [t, hr.Pressure];
633 var te = [t, hr.Temp_Out];
634 var hu = [t, hr.Humidity_Out];
636 // do_debug(js.tm + " " + t + " " + te + "<br>");
637 daychart.series[0].addPoint(ra, true, rainfall);
638 daychart.series[1].addPoint(pr, true, pressure);
639 daychart.series[2].addPoint(te, true, temp);
640 daychart.series[3].addPoint(hu, true, humidity);
645 function fill_windrose(rr, points) {
646 var p = windrose.series[0].data.length > points;
647 var v = [rr.Dir, (rr.Wind*conv)];
648 windrose.series[0].addPoint(v, true, p);
651 function fill_windspeed(rr) {
652 var point = windspeed.series[0].points[0];
653 point.update(Math.round(rr.Wind*conv));
656 function fill_winddir(rr) {
657 var point = winddir.series[0].points[0];
658 point.update(rr.Dir);
661 window.onload = function() {
667 window.setInterval(function() {
676 <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
680 <table border="0" align="center">
682 <td id="windrose" style="min-width: 350px; max-width: 400px; height: 330px; margin: 0 auto"> </td>
683 <td id="windspeed" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
684 <td id="winddir" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
690 <div id="start-template">
692 <table class="table">
694 <th width="7%">Time:</th><td width="7%"><span id="tm"> </span></td>
695 <th width="7%">Sunrise:</th><td width="7%"><span id="Sunrise"> </span></td>
696 <th width="7%">Sunset:</th><td width="7%"><span id="Sunset"> </span></td>
697 <th width="7%">Console Volts:</th><td width="7%"><span id="Batt_Console"> </span></td>
698 <th width="7%">TX Battery OK:</th><td width="7%"><span id="Batt_TX_OK"> </span></td>
701 <th>Pressure:</th><td><span id="Pressure"> </span> mb</td>
702 <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
705 <th>Temperature in:</th><td> <span id="Temp_In"> </span> °C</td>
706 <th>Humidity:</th><td> <span id="Humidity_In"> </span> %</td>
708 <tr><th>Temperature out:</th><td> <span id="Temp_Out"> </span> °C</td>
709 <th>Min:</th><td> <span id="Temp_Out_Min"> </span> °C @ <span id="Temp_Out_Min_T"> </span></td>
710 <th>Max:</th><td> <span id="Temp_Out_Max"> </span> °C @ <span id="Temp_Out_Max_T"> </span></td>
711 <th>Humidity:</th><td> <span id="Humidity_Out"> </span> %</td>
712 <th>Dew Point:</th><td> <span id="Dew_Point"> </span> °C</td>
714 <tr><th>Wind:</th><td><span id="Dir"> </span> ° @ <span id="Wind"> </span> m/s</td>
715 <th>Wind Minute Avg:</th><td> <span id="Dir_1m"> </span> ° @ <span id="Wind_1m"> </span> m/s </td>
716 <th>Day Max Speed:</th><td> <span id="Wind_Max"> </span> m/s @ <span id="Wind_Max_T"> </span></td>
719 <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span> mm</td>
720 <th>Day:</th><td> <span id="Rain_Day"> </span> mm</td>
721 <th>24hrs:</th><td> <span id="Rain_24h"> </span> mm</td>
722 <th>Month:</th><td> <span id="Rain_Month"> </span> mm</td>
723 <th>Year:</th><td> <span id="Rain_Year"> </span> mm</td>
730 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
731 <script src="js/jquery.min.js"></script>
732 <!-- Latest compiled and minified JavaScript -->
733 <script src="js/bootstrap.min.js"></script>
734 <!-- High Chart stuff -->
735 <script src="js/highcharts.js"></script>
736 <script src="js/highcharts-more.js"></script>
737 <script src="js/modules/exporting.js"></script>