2 % my $url = url_for 'weather';
7 <title>DWeather</title>
9 <meta http-equiv="X-UA-Compatible" content="IE=edge">
10 <meta name="viewport" content="width=device-width, initial-scale=1">
12 <!-- Latest compiled and minified CSS -->
13 <link rel="stylesheet" href="css/bootstrap.min.css">
15 <!-- Optional theme -->
16 <link rel="stylesheet" href="css/bootstrap-theme.min.css">
18 <!-- auto refresh (really only for the yr.no forecast) -->
19 <meta content="3600" http-equiv="Refresh">
24 <center><h1>High View Weather</h1></center>
29 var daychart_days = <%= $main::histdays %>;
31 var windrose_mins = <%= $main::windmins %>;
34 var updatespermin = <%= $main::updatepermin %>;
39 "Wind" : function (speed) { return (speed * 2.236936).toFixed(1); },
40 "Wind_1m" : function (speed) { return (speed * 2.236936).toFixed(1); },
41 "Wind_Max": function (speed) { return (speed * 2.236936).toFixed(1); }
45 function do_debug(text) {
46 document.getElementById("do_debug").innerHTML = text;
49 function update_h(key, value) {
53 function fill_html(key,value) {
54 var d = document.getElementById(key);
57 if (f && typeof(f) === "function") {
58 d.innerHTML = trans[key](value);
65 function traverse(o, func) {
68 if (o[i] !== null && typeof(o[i])==="object") {
82 ws = new WebSocket('<%= $url->to_abs %>');
84 if (typeof(ws) !== null) {
85 ws.onmessage = function (event) {
86 var js = JSON.parse(event.data);
87 if (js !== null && typeof(js) === 'object') {
88 traverse(js, fill_html);
89 // traverse(js, update_h);
90 // document.getElementById("hh").innerHTML = JSON.stringify(h);
92 fill_daychart(js, daychart_days);
94 if ("r" in js || "m" in js) {
101 fill_windrose(rr, windrose_mins * updatespermin);
109 ws.onopen = function (event) {
110 document.getElementById("wsconnect").innerHTML = 'ws connected to: <%= $url->to_abs %>';
111 ws.send('WebSocket support works!');
113 ws.onclose = function(event) {
114 document.getElementById("wsconnect").innerHTML = 'ws disconnected, refresh to restart';
118 document.body.innerHTML += 'Webserver only works with Websocket aware browsers';
122 function start_daychart() {
123 daychart = new Highcharts.Chart({
125 renderTo: 'daychart',
129 text: 'Last Five Days'
136 yAxis: [{ // Temperature +(ve)
156 color: Highcharts.getOptions().colors[0]
160 format: '{value} mm',
162 color: Highcharts.getOptions().colors[0]
169 text: 'Sea-Level Pressure',
175 format: '{value} mb',
198 }, { // Temperature -(ve)
206 // text: 'Temperature',
218 // layout: 'vertical',
221 // verticalAlign: 'top',
224 // backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
237 color: Highcharts.getOptions().colors[0],
240 // format: '{point.y:.1f}', // one decimal
246 for (@main::last5daysh) {
247 my $r = $main::json->decode($_);
248 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r && exists $r->{t} && exists $r->{h}->{Rain_1h};
250 chop $s if length $s;
258 name: 'Sea-Level Pressure',
264 for (@main::last5daysh) {
265 my $r = $main::json->decode($_);
266 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r && exists $r->{t} && exists $r->{h}->{Pressure};
268 chop $s if length $s;
274 dashStyle: 'shortdot',
280 name: 'Temperature +(ve)',
285 <% $s = ""; undef $lasttemp;
286 for (@main::last5daysh) {
287 my $r = $main::json->decode($_);
288 if ($r && exists $r->{t} && exists $r->{h}->{Temp_Out}) {
289 my $temp = $r->{h}->{Temp_Out};
290 my $tm = $r->{t}*1000;
291 $lasttemp = $temp unless defined $lasttemp;
293 $s .= sprintf "[%s,0],", $tm-1 if $lasttemp <= 0;
294 $s .= sprintf "[%s,%s],", $tm, $temp;
296 $s .= sprintf "[%s,%s],", $tm, $lasttemp > 0 ? 0 : "null";
301 chop $s if length $s;
315 for (@main::last5daysh) {
316 my $r = $main::json->decode($_);
317 $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Humidity_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Humidity_Out};
319 chop $s if length $s;
325 dashStyle: 'shortdot',
330 name: 'Temperature -(ve)',
335 <% $s = ""; undef $lasttemp;
336 for (@main::last5daysh) {
337 my $r = $main::json->decode($_);
338 if ($r && exists $r->{t} && exists $r->{h}->{Temp_Out}) {
339 my $temp = $r->{h}->{Temp_Out};
340 my $tm = $r->{t}*1000;
341 $lasttemp = $temp unless defined $lasttemp;
343 $s .= sprintf "[%s,0],", $tm-1 if $lasttemp > 0;
344 $s .= sprintf "[%s,%s],", $tm, $temp;
346 $s .= sprintf "[%s,%s],", $tm, $lasttemp <= 0 ? 0 : "null";
351 chop $s if length $s;
362 function start_windrose() {
365 Highcharts.createElement('link', {
366 href: '//fonts.googleapis.com/css?family=Dosis:400,600',
369 }, null, document.getElementsByTagName('head')[0]);
372 colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee",
373 "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"],
375 backgroundColor: null,
377 fontFamily: "Dosis, sans-serif"
384 textTransform: 'uppercase'
389 backgroundColor: 'rgba(219,219,216,0.8)',
407 minorTickInterval: 'auto',
410 textTransform: 'uppercase'
427 background2: '#F0F0EA'
432 Highcharts.setOptions(Highcharts.theme);
434 windrose = new Highcharts.Chart({
454 formatter: function () {
455 return this.value + '°';
489 for (@main::last10minsr) {
490 my $r = $main::json->decode($_);
492 $r->{r}->{Dir} ||= $d;
493 $r->{r}->{Wind} ||= $w;
494 $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "],";
496 $w = $r->{r}->{Wind};
499 chop $s if length $s;
506 function start_windspeed() {
507 windspeed = new Highcharts.Chart({
510 renderTo: 'windspeed',
511 plotBackgroundColor: null,
512 plotBackgroundImage: null,
526 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
536 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
545 // default background
547 backgroundColor: '#DDD',
559 minorTickInterval: 'auto',
562 minorTickPosition: 'inside',
563 minorTickColor: '#666',
565 tickPixelInterval: 30,
567 tickPosition: 'inside',
580 color: '#55BF3B' // green
584 color: '#DDDF0D' // yellow
588 color: '#DF5353' // red
609 function start_winddir() {
610 winddir = new Highcharts.Chart({
614 plotBackgroundColor: null,
615 plotBackgroundImage: null,
621 text: 'Wind Direction'
629 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
639 linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
648 // default background
650 backgroundColor: '#DDD',
662 minorTickInterval: 'auto',
665 minorTickPosition: 'inside',
666 minorTickColor: '#666',
668 tickPixelInterval: 15,
670 tickPosition: 'inside',
693 valueSuffix: ' ° deg'
699 function fill_daychart(js, days) {
700 var rainfall = daychart.series[0].data.length > (days * 48);
701 var pressure = daychart.series[1].data.length > (days * 48);
702 var temppos = daychart.series[2].data.length > (days * 48);
703 var tempneg = daychart.series[4].data.length > (days * 48);
704 var humidity = daychart.series[3].data.length > (days * 48);
708 var ra = [t, hr.Rain_1h];
709 var pr = [t, hr.Pressure];
710 var te = [t, hr.Temp_Out];
711 var hu = [t, hr.Humidity_Out];
713 // do_debug(js.tm + " " + t + " " + te + "<br>");
714 daychart.series[0].addPoint(ra, true, rainfall);
715 daychart.series[1].addPoint(pr, true, pressure);
716 if (lasttemp <= -100) {
717 lasttemp = hr.Temp_Out;
719 if (hr.Temp_Out > 0) {
721 daychart.series[2].addPoint([t, 0], true, temppos);
723 daychart.series[2].addPoint([t, hr.Temp_Out], true, temppos);
725 daychart.series[2].addPoint([t, (lasttemp > 0) ? 0 : null], true, temppos);
727 if (hr.Temp_Out <= 0) {
729 daychart.series[4].addPoint([t, 0], true, temppos);
731 daychart.series[4].addPoint([t, hr.Temp_Out], true, tempneg);
733 daychart.series[4].addPoint([t, (lasttemp <= 0) ? 0 : null], true, tempneg);
735 lasttemp = hr.Temp_Out;
736 daychart.series[3].addPoint(hu, true, humidity);
741 function fill_windrose(rr, points) {
742 var p = windrose.series[0].data.length > points;
743 var v = [rr.Dir, (rr.Wind*conv)];
744 windrose.series[0].addPoint(v, true, p);
747 function fill_windspeed(rr) {
748 var point = windspeed.series[0].points[0];
749 point.update(Math.round(rr.Wind*conv));
752 function fill_winddir(rr) {
753 var point = winddir.series[0].points[0];
754 point.update(rr.Dir);
757 window.onload = function() {
763 window.setInterval(function() {
773 <h4>Two Day Forecast</h2>
774 <a href="http://www.yr.no/place/United_Kingdom/England/Graffham~2648243/hour_by_hour.html"><img src="http://www.yr.no/place/United_Kingdom/England/Graffham~2648243/avansert_meteogram.png" alt="meteogram" title="" height="295" width="810"></a>
779 <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
783 <table border="0" align="center">
785 <td id="windrose" style="min-width: 350px; max-width: 400px; height: 330px; margin: 0 auto"> </td>
786 <td id="windspeed" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
787 <td id="winddir" style="min-width: 280px; max-width: 400px; height: 270px; margin: 0 auto"> </td>
793 <div id="start-template">
795 <table class="table">
797 <th width="7%">Time:</th><td width="7%"><span id="tm"> </span></td>
798 <th width="7%">Sunrise:</th><td width="7%"><span id="Sunrise"> </span></td>
799 <th width="7%">Sunset:</th><td width="7%"><span id="Sunset"> </span></td>
800 <th width="7%">Console Volts:</th><td width="7%"><span id="Batt_Console"> </span></td>
801 <th width="7%">TX Battery OK:</th><td width="7%"><span id="Batt_TX_OK"> </span></td>
804 <th>Pressure:</th><td><span id="Pressure"> </span> mb</td>
805 <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
808 <th>Temperature in:</th><td> <span id="Temp_In"> </span> °C</td>
809 <th>Humidity:</th><td> <span id="Humidity_In"> </span> %</td>
811 <tr><th>Temperature out:</th><td> <span id="Temp_Out"> </span> °C</td>
812 <th>Min:</th><td> <span id="Temp_Out_Min"> </span> °C @ <span id="Temp_Out_Min_T"> </span></td>
813 <th>Max:</th><td> <span id="Temp_Out_Max"> </span> °C @ <span id="Temp_Out_Max_T"> </span></td>
814 <th>Humidity:</th><td> <span id="Humidity_Out"> </span> %</td>
815 <th>Dew Point:</th><td> <span id="Dew_Point"> </span> °C</td>
817 <tr><th>Wind:</th><td><span id="Dir"> </span> ° @ <span id="Wind"> </span> mph</td>
818 <th>Wind Minute Avg:</th><td> <span id="Dir_1m"> </span> ° @ <span id="Wind_1m"> </span> mph </td>
819 <th>Day Max Speed:</th><td> <span id="Wind_Max"> </span> mph @ <span id="Wind_Max_T"> </span></td>
822 <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span> mm</td>
823 <th>Day:</th><td> <span id="Rain_Day"> </span> mm</td>
824 <th>24hrs:</th><td> <span id="Rain_24h"> </span> mm</td>
825 <th>Month:</th><td> <span id="Rain_Month"> </span> mm</td>
826 <th>Year:</th><td> <span id="Rain_Year"> </span> mm</td>
833 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
834 <script src="js/jquery.min.js"></script>
835 <!-- Latest compiled and minified JavaScript -->
836 <script src="js/bootstrap.min.js"></script>
837 <!-- High Chart stuff -->
838 <script src="js/highcharts.js"></script>
839 <script src="js/highcharts-more.js"></script>
840 <script src="js/modules/exporting.js"></script>