Author Topic: What can I do with php? See example  (Read 1619 times)

0 Members and 1 Guest are viewing this topic.

Offline smorris

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 568
    • Long Road Station
What can I do with php? See example
« on: February 05, 2012, 11:48:52 PM »
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:
Code: [Select]
<?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:
Code: [Select]
<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($handlefilesize($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:
Code: [Select]
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.php


Like 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
« Last Edit: February 05, 2012, 11:51:58 PM by smorris »
Steve - Avon, Ohio
Davis Vantage Pro2 Plus w/FARS, Leaf & Soil Station

CWOP • WU • AWEKAS • CoCoRaHS • Skywarn • MWWN • UK Met • PWS • WeatherBug • TwitterFacebook

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Re: What can I do with php? See example
« Reply #1 on: February 07, 2012, 07:28:34 AM »
Steve,

I went to your avon-weather homepage (following your sig link) and I didn't see anything that looked like your example, unless your dial-graphs are parsed from that info.  Are you talking about a page somewhere else?  There is no <meta refresh> tag in the source on that page, like in your example code.  A manual page referesh seems to update the "current conditions" time every five minutes.  That tag would do it, so I think I am not looking in the right place.


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline Axelvold

  • Forecaster
  • *****
  • Posts: 1704
    • Axelvold's weather and photo
Re: What can I do with php? See example
« Reply #2 on: February 07, 2012, 08:12:29 AM »
Steve,

I went to your avon-weather homepage (following your sig link) and I didn't see anything that looked like your example, unless your dial-graphs are parsed from that info.  Are you talking about a page somewhere else?  There is no <meta refresh> tag in the source on that page, like in your example code.  A manual page referesh seems to update the "current conditions" time every five minutes.  That tag would do it, so I think I am not looking in the right place.

You should have followed this link.

And here's the web page showing the constantly updating data:
http://www.avon-weather.com/test_php/watch_weather.php
Lars Magnusson
Axelvold / Sweden
55° 57' 41" N / 13° 6' 1" E
WX Station: Davis Vantage Pro2 Plus

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Re: What can I do with php? See example
« Reply #3 on: February 07, 2012, 08:19:00 AM »
Steve,

I went to your avon-weather homepage (following your sig link) and I didn't see anything that looked like your example, unless your dial-graphs are parsed from that info.  Are you talking about a page somewhere else?  There is no <meta refresh> tag in the source on that page, like in your example code.  A manual page referesh seems to update the "current conditions" time every five minutes.  That tag would do it, so I think I am not looking in the right place.

You should have followed this link.

And here's the web page showing the constantly updating data:
http://www.avon-weather.com/test_php/watch_weather.php

Right you are, Lars...  Forest for the trees and all that...

Steve, How about uploading it comma delimited instead of text-formatted, like for your sig banner, and using the same anole wxgraphic script on a page that refreshes like that?  That's about as basic as it gets and will give you some fun learning to play with php.


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline smorris

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 568
    • Long Road Station
Re: What can I do with php? See example
« Reply #4 on: February 07, 2012, 08:41:36 AM »
Thanks guys!

xykotk: That's an interesting suggestion in having just a basic live data page (a nice looking version of the text only in the link.) I don't know if I could use what LWC is exporting for any of the animation templates some of you use such as the live wind rose/wind speed. Or with one of the thermometer scripts.

THanks
Steve
Steve - Avon, Ohio
Davis Vantage Pro2 Plus w/FARS, Leaf & Soil Station

CWOP • WU • AWEKAS • CoCoRaHS • Skywarn • MWWN • UK Met • PWS • WeatherBug • TwitterFacebook

Offline xykotik

  • DonkeyTailWX DW6891
  • Forecaster
  • *****
  • Posts: 696
  • I'll deal with it tomorrow
    • DonkeyTail Weather
Re: What can I do with php? See example
« Reply #5 on: February 07, 2012, 10:03:17 AM »
Thanks guys!

xykotk: That's an interesting suggestion in having just a basic live data page (a nice looking version of the text only in the link.) I don't know if I could use what LWC is exporting for any of the animation templates some of you use such as the live wind rose/wind speed. Or with one of the thermometer scripts.

THanks
Steve

You mentioned WU Rapid-fire so I was thinking about the oversized sticker they have for that (with the photo-bg).  If you can get something basic working (with the text only) maybe work on fancy wind-rose and thermomter graphics later.  Share your progress.  I believe that is how Anole got the whole wxgraphic thing going in the first place, learning php by making a wx-banner from weathertag uploads.


Facit solem suum oriri super bonos et malos et pluit super iustos et iniustos.

Springtime in Seattle...  March comes in like a lion and out like a wet lion.

Offline smorris

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 568
    • Long Road Station
Re: What can I do with php? See example
« Reply #6 on: February 07, 2012, 10:15:04 AM »
You mentioned WU Rapid-fire so I was thinking about the oversized sticker they have for that (with the photo-bg).  If you can get something basic working (with the text only) maybe work on fancy wind-rose and thermomter graphics later.  Share your progress.  I believe that is how Anole got the whole wxgraphic thing going in the first place, learning php by making a wx-banner from weathertag uploads.

Ah, OK. I see why you suggested that. I looked at the Anole wxgraphic, and it is an image just like I generate within LWC2. I see your point about making is similar but with live data. I'll play with that.

Thanks,
Steve
Steve - Avon, Ohio
Davis Vantage Pro2 Plus w/FARS, Leaf & Soil Station

CWOP • WU • AWEKAS • CoCoRaHS • Skywarn • MWWN • UK Met • PWS • WeatherBug • TwitterFacebook

 

anything