Hi gang,
Please bear with me, as I'm not really too sure what I'm asking nor what is possible with php.
I use Lightsoft Weather Center on my Macintosh. I've been happy with the tags available for custom web page generation and AppleScripts. I'm able to send data to all the usual places as well as post Twitter updates and populate my web page. The only option I haven't explored with the software is the Custom CGI output. Today I set up the sample included with the software and get results posted online every two seconds. It seems like it would be nice to have a "live" current conditions similar to Weather Underground's Rapid Fire, but I don't know what is possible.
I figure the best way to learn is to ask for you guys to take a look at what I've got and maybe you can suggest some options.
Here's my php script:
<?php
// Script by Lightsoft - http://www.lightsoft.co.uk
// Use with LWC Custom CGI feature
//
// Provides receipt of weather data to the server and stores in a simple file. Has to be a server side
// script but theoretically need not be PHP. Other options are Perl CGI, Python, etc - depending upon
// what your web server supports.
//
// We assume security of the username/password is not critical (sent as plain text). We limit what
// data we accept and try to ensure all sequences from the GET are properly stripped before use
// on a web page.
//
// We use a GET rather than POST since data is very limited and doesn't overly affect server operation.
//
$success = 0;
$line_end = "<br>\r\n";
if(htmlspecialchars($_GET['action']) === 'update') // what do we want to do?
{
if(htmlspecialchars($_GET['ID']) === 'xxxxxx') // the user name allowed to update the data (***CHANGE THIS!***)
{
if(htmlspecialchars($_GET['PASSWORD']) === 'xxxxxx') // the password of that user (***CHANGE THIS!***)
{
$output = "";
$output .= "Date (UTC): " . htmlspecialchars($_GET['dateutc']) . $line_end; // 2008-02-10+11%3A20%3A39
$output .= "Wind dir (deg): " . (float)($_GET['winddir']) . $line_end; // 230
$output .= "Wind Speed (mph): " . (float)($_GET['windspeedmph']) . $line_end; //12
$output .= "Wind Speed (mphAv10mins): " . (float)($_GET['windspeedmphav_10m']) . $line_end; //12
$output .= "Wind Gust (mph): " . (float)($_GET['windgustmph']) . $line_end; // 12
$output .= "Wind Gust (dir): " . (float)($_GET['windgustdir']) . $line_end; // 12
$output .= "Wind Gust (mph10mins): " . (float)($_GET['windgustmph_10m']) . $line_end; // 12
$output .= "Wind Gust (dir10mins): " . (float)($_GET['windgustdir_10m']) . $line_end; // 12
$output .= "Humidity: " . (float)($_GET['humidity']) . $line_end; // 90
$output .= "Dew Point (F): " . (float)($_GET['dewptf']) . $line_end; // 68.2
$output .= "Temp (F): " . (float)($_GET['tempf']) . $line_end; // 12
$output .= "Rain (in): " . (float)($_GET['raininch']) . $line_end; // 0
$output .= "Rain24h (in): " . (float)($_GET['rain24hinch']) . $line_end; // 0
$output .= "Barom (in): " . (float)($_GET['baroinch']) . $line_end; // 29.1
$output .= "Conditions: " . htmlspecialchars($_GET['weather']) . $line_end; // Sunny
//echo $output; // for testing
if(($handle = fopen("weather_data.txt","wb")) !== FALSE)
{
$write_status = fwrite($handle, $output); // we ignore write status (FALSE on fail or bytes written)
$close_status = fclose($handle); // we ignore close status (FALSE failure, TRUE on success)
$success = 1;
}
}
}
}
if($success==0)
{
echo 'Fail';
}
else
{
echo 'OK';
}
?>
Here's an image of the data it generates:

Here's the web html to display the data:
<html>
<head>
<title>Weather Watch</title>
<meta http-equiv="refresh" content="2">
</head>
<body>
<p>
<?php
// This script just loads the weather data. You could do other processing of the
// weather data as well.
// Three other options to include the weather data in the html page (other than the
// PHP code below that is) are to use Perl CGI, Server Side Includes (SSI) or
// Javascript (client side processing).
//
// OTHER NOTES
// You might want to use the following tag if the page doesn't refresh new data due
// to caching. The full URL should mean caching doesn't occur.
// Remember to change the URL to your own site!
// The number is the refresh period in seconds. We suggest not making it too small.
// <meta http-equiv="refresh" content="10; url=http://www.lightsoft.co.uk/watch_weather.php">
$filename = "weather_data.txt";
if(($handle = fopen($filename,"rb")) !== FALSE)
{
$contents = fread($handle, filesize($filename));
echo $contents;
$close_status = fclose($handle); // we ignore close status (FALSE failure, TRUE on success)
}
?>
</p>
<p>
(Page refreshes every 2 seconds)<br>
PHP script by Lightsoft - <a href="http://www.lightsoft.co.uk">www.lightsoft.co.uk</a>
</p>
</body>
</html>
Here's the "weather_data.txt called in the above:
Date (UTC): 2012-02-06 04:50:09<br>
Wind dir (deg): 189<br>
Wind Speed (mph): 5<br>
Wind Speed (mphAv10mins): 3<br>
Wind Gust (mph): 5<br>
Wind Gust (dir): 196<br>
Wind Gust (mph10mins): 7<br>
Wind Gust (dir10mins): 221<br>
Humidity: 79<br>
Dew Point (F): 27.406<br>
Temp (F): 33.2<br>
Rain (in): 0<br>
Rain24h (in): 0<br>
Barom (in): 30.26<br>
Conditions: <br>
And here's the web page showing the constantly updating data:
http://www.avon-weather.com/test_php/watch_weather.phpLike I said, be gentle, as this stuff is way over my head. I can do basic html and that's about it (see my web site linked in my sig for an idea how simple it is.) Seeing what you see, is there anything interesting I can do with this data other than simply display it as text like in the example?
Thanks for taking the time to look through this,
Steve