- Create windspeed RRD data file:
rrdtool create sbwind.rrd \
--start 1127253600 \
DS:wind:GAUGE:600:U:U \
DS:gust:GAUGE:600:U:U \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:288:797 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
- Create wind direction RRD data file:
rrdtool create sbwinddir.rrd \
--start 1127253600 \
DS:wind_direction:GAUGE:600:0:360 \
RRA:AVERAGE:0.5:1:600
update_rrd_data.php
<?php
// 2010-02-22 - testing simplexml
/*
- ellwood: http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MSBELL
- bel air: http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASANTA122
- mesa : http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS714
- cumbre : http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS303
- airport: http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MKSBA
*/
// setup variables
$debug = 1;
$a = array();
$a['ellwood'] = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MSBELL';
$a['belair'] = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASANTA122';
$a['mesa'] = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS714';
$a['lacumbre'] = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS303';
$a['airport'] = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MKSBA';
$wdir = "/var/www/redigital.org/sbwindi/xml";
// loop through the locations and update the graphs
foreach ($a as $location => $value) {
$xml_url = $value;
$wind_data = simplexml_load_file($xml_url);
//$wind_data = $xml;
$wind_mph = $wind_data->wind_mph;
$wind_gust_mph = $wind_data->wind_gust_mph;
if ($wind_gust_mph == "0")
$wind_gust_mph = $wind_mph;
$wind_direction = $wind_data->wind_direction;
$wind_degrees = $wind_data->wind_degrees;
$wind_string = $wind_data->wind_string;
//$update_rrd_data_cmd = "/usr/bin/rrdtool update ${wdir}/${location}.rrd \"N:${wind_mph}:${wind_gust_mph}\"";
//$update_rrd_data = `$update_rrd_data_cmd`;
$update_dir_data_cmd = "/usr/bin/rrdtool update ${wdir}/${location}_dir.rrd \"N:${wind_degrees}\"";
$update_dir_data = `$update_dir_data_cmd`;
$update_graph_cmd = "/usr/bin/rrdtool graph ${wdir}/${location}_d.png \
-M -v mph -t ${location}-'${wind_string}' -w 320 --height=120 --alt-autoscale-max --lower-limit=0 -s 09:00 -e 20:00 \
DEF:a=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:b=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:c=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:d=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:e=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:f=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:g=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:h=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:i=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:j=${wdir}/${location}.rrd:wind:AVERAGE \
DEF:ba=${wdir}/${location}.rrd:gust:AVERAGE \
DEF:bb=${wdir}/${location}.rrd:wind:AVERAGE \
CDEF:cdefa=i,0,GE,i,22.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefb=i,22.6,GE,i,67.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefc=i,67.6,GE,i,112.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefd=i,112.6,GE,i,157.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefe=i,157.6,GE,i,202.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdeff=i,202.6,GE,i,247.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefg=i,247.6,GE,i,292.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefh=i,292.6,GE,i,337.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefi=i,337.6,GT,i,360.99,GT,UNKN,INF,IF,UNKN,IF \
AREA:cdefa#8D85F3:\"North\" \
AREA:cdefb#9FA4EE:\"North East\" \
AREA:cdefc#F9FD5F:\"East\" \
AREA:cdefd#EACC00:\"South East\\n\" \
AREA:cdefe#EAAF00:\"South\" \
AREA:cdeff#EA8F00:\"South West\" \
AREA:cdefg#00CF00:\"West\" \
AREA:cdefh#6557D0:\"North West\\n\" \
AREA:cdefi#8D85F3:\"\" \
GPRINT:i:LAST:\"Current Direction in Degrees\:%8.2lf %s\\n\" \
AREA:bb#C0C0C0:\"\" \
LINE2:ba#562B29:\"\" \
LINE1:bb#000000:\"\"
";
$update_graph = `$update_graph_cmd`;
if ( $debug ) {
echo "<p>\n";
echo "<h2> location = ${location}</h2>\n";
echo "<h3> url = ${value}</h3>\n";
echo "<img src=${location}_d.png><br>\n";
echo "<pre>\n";
print_r($wind_data);
echo $update_dir_data_cmd . "<br>";
echo $update_graph_cmd . "<br>";
echo "</pre></p><hr>\n";
}
}
?>
index.php
<?php
#20100524 - randall s. ehren <randall@redigital.org>
$base_path = "/sbwindi/";
?>
<html>
<head>
<!-- render the page for iphones well -->
<meta name="viewport" content="width=device-width,minimum-scale=1.0, initial-scale=1" />
<title>iphone bel air knolls wind graph</title>
<style>
@media screen and (max-device-width: 480px){
/*--- iPhone only CSS here ---*/
body{
-webkit-text-size-adjust:none;
/* font-family:Helvetica, Arial, Verdana, sans-serif; */
margin:0;
padding:0;
}
}
#menubar ul {
list-style: none;
padding: 0;
margin: 0;
}
#menubar li {
float: left;
margin: 0 0em;
}
#menubar li a {
background: url(css-nav.gif) #fff bottom left repeat-x;
height: 2em;
line-height: 2em;
float: left;
width: 3.9em;
display: block;
border: 0.1em solid #dcdce9;
color: #0d2474;
text-decoration: none;
text-align: center;
}
#content {
}
</style>
</head>
<body>
<div id="header">
<div id="menubar">
<ul>
<li><a href="<?=$_SERVER[PHP_SELF]?>?l=airport">airport</a></li>
<li><a href="<?=$_SERVER[PHP_SELF]?>?l=ellwood">ellwood</a></li>
<li><a href="<?=$_SERVER[PHP_SELF]?>?l=belair">belair</a></li>
<li><a href="<?=$_SERVER[PHP_SELF]?>?l=lacumbre">lacumbre</a></li>
<li><a href="<?=$_SERVER[PHP_SELF]?>?l=mesa">mesa</a></li>
</ul>
</div>
</div>
<p>
<div id="content" align="left">
<?php
function display_wind_graphs($location)
{
echo "<br><br>\n";
echo "<img src=\"/sbwindi/xml/${location}_d.png\" width=\"320\" alt=\"${location}\">";
echo "<br>\n";
echo "<img src=\"/sbwindi/xml/${location}_h.png\" width=\"320\" alt=\"${location}\">";
}
$location = $_GET["l"];
switch ($location) {
case "airport":
$loc_name = "Airport";
//echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MKSBA"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MKSBA" width="250" height="150" border="0" alt="Weather Underground PWS MKSBA" /></a>';
display_wind_graphs($location);
break;
case "mesa":
$loc_name = "Mesa";
//echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MAS714"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MAS714" width="250" height="150" border="0" alt="Weather Underground PWS MAS714" /></a>';
display_wind_graphs($location);
break;
case "ellwood":
$loc_name = "Mesa";
//echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MSBELL"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MSBELL" width="250" height="150" border="0" alt="Weather Underground PWS MSBELL" /></a>';
display_wind_graphs($location);
break;
case "lacumbre":
//echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MAS303"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MAS303" width="250" height="150" border="0" alt="Weather Underground PWS MAS303" /></a>';
display_wind_graphs($location);
break;
case "belair":
//echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KCASANTA122"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=KCASANTA122" width="250" height="150" border="0" alt="Weather Underground PWS KCASANTA122" /></a>';
display_wind_graphs($location);
break;
}
?>
</div>
</body>
</html>