extracting certain data from WD

Hi Guys,

I have been offered to supply an international weather station our live wind report from WD for our region and they have asked me for the following information to be uploaded in a Text file to there server every 15 minutes, has anyone any idea how i can get this data in a text file automatically in this format every 15 minutes?

Format:
1.Name \t 2.3.4.day-month-year \t 5.hour:6.minutes \t 7.airtemp \t 8.max air temp \t 9.min air temp \t 10.windspeed \t 11.gusts \t 12.wind direction in degrees (0-360) \t 13.Pressure (in hPa)

Example:
Fuerteventura \t 10.11.2003 \t 19:47 \t 21.4 \t 23.5 \t 19.3 \t 18.4 \t 21.0 \t 45 \t 1021.4

Explanation:
\t symbolizes a tab but can be written as \t as well
decimal places are separated by dot (.) or comma (,) or can be skipped
the elements of the date can be separated by dots (.) or minus (-)
single values can be missing but have to be indicated with a tab

thanks in advance

A PHP method using data the clientraw.txt file (assuming you are sending it to a webserver already).

The following source reads the clientraw.txt file and outputs the data you are asking in the format you asked for.

Source:
http://www.tnetweather.com/test/windywill01.phps

Sample “Live” Output (info from TNETWeather):
http://www.tnetweather.com/test/windywill01.php

Not included is how to send the data to their server. It is assumed you could use crontab to schedule it.

You could do the same thing with WD, and use it to send it via FTP… but this is more fun…

Hi Tnet,

Many thanks for this mate, really appreciate it.

Any chance you could give me a short tutorial on integrating all of this including the upload to the recipricants FTP?

Should i just upload the PHP file to the server and set a cron job to run the script and send the data to the webserver?

Willy

The source code has been modified to add the ability for it to create a file (weatherinfo.txt) and then FTP the file to the ftp server. The new code is prevented from executing by an exit.

You need to do several things to use it…

  1. create a file called weatherinfo.txt (or whatever filename you need to send) on your webserver and make sure it has chmod 666 permissions.

  2. Edit the script to:

a) comment out the echo to screen
b) remove the exit; after the echo
c) correct the filename name if you use something other than weatherinfo.txt
d) place the ftp server name you need to send to

$ftp_server = “ftp.example.com”;

e) set the user and pass

$ftp_user = “foo”;
$ftp_pass = “bar”;

When you have made those changes it should work… I’ve not tried the ftp portion…

Kevin - you go to a great length to develope code and then provide very distinct steps for the user. Well done!

Graeme

Kevin you are absolutely amazing! Thanks for the help!

To run the script every 15 minutes what are you using? Cron Job?

WindyWill

you could also use the custom file creation (via the special file conversion) ability in wd and the custom tags…

Hi Kevin,

i have finally got this too work to a certain level.

Problem i have is that i want to upload the output file to a certain folder on the server.

so i have set the ftp settings on the php

$ftp_server = “ftp.example.com”;
$ftp_user = “foo”;
$ftp_pass = “bar”;

so how do i get it to upload to a sub directory on the server?

Lets say i want to upload to example.com/wind ?

where do i set the destination folder for the upload in the PHP file

Thanks for your help

Windywill

You have to add a line to change the directory http://www.w3schools.com/PHP/func_ftp_chdir.asp

Correct.

I updated the source to include a commented out section that would do that.

// If you needed to change to a directory like weather
// you would uncomment this section...

if (@ftp_chdir($conn_id, "weather")) {
    echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else { 
    echo "Couldn't change directory\n";
}

Thanks Kevin,

im getting an error

Warning: ftp_fput() [function.ftp-fput]: willys_test.txt: Permission denied in /var/www/vhosts/example.com/httpdocs/wind_test.php on line 115
There was a problem while uploading willys_test.txt

i have set the chmod permissions to 666

also using your updated code it is saying - Couldn’t change directory

cheers

Windywill

That would be the problem… the chdir failed, so you are attempting to chdir to a directory that is either not there or you don’t have permissions to.

Hi Kevin,

ok so i commented out the directory change code you added and i still receive the previous error.

Warning: ftp_fput() [function.ftp-fput]: willys_test.txt: Permission denied in /var/www/vhosts/example.com/httpdocs/wind_test.php on line 115
There was a problem while uploading willys_test.txt

ok got it sorted,

actually my destination path was wrong, just ensure to supply the entire path from root of the FTP, for example all the visible files on this domain are in httpdocs so to get the chdir to “windtest” i was required to change the code to httpdocs/windtest

It is telling you exactly what the error is…

Permission denied

in /var/www/vhosts/example.com/httpdocs/wind_test.php

on line 115