Page 1 of 3

Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:23 pm
by phtvs
Because I want to use the information from realtime.txt in my website script, I made this tiny script to read the realtime.txt file and put the info from that file in variables.

Usage of the script:

include the view-realtime.php in your script. Now you can use the strings to print the info on your website

for testing the script, point your browser to:
http://linktoyoursite/view-realtime.php?action=view


For more instructions, read the comments in the script.

Have fun with it!

Theo


EDIT: Filecheck added to the script.
EDIT: Made a change to the filecheck. (Thanks to Steve for the tip!)

EDIT: Made another usefull script for using with the view-realtime.php script.

EDIT: Update of the script. now without errors

This script shows a table with all the strings that are used by the view-realtime-helper.php script

Unpack the .rar with winrar and put the realtime-helper.php script in the same directory as the view-realtime.php file.

Point your browser to:

http://www.linktoyoursite/realtime-helper.php

EDIT: To show what nice things you can do with the view-realtime.php script I have made a webpage.

DEMO: http://www.weerstation-lemmer.nl/cumulu ... onsole.php

This is a weatherconsole with "live"updates. Page refreshes every 15 seconds. (Could be more or less if you want)


Have fun with it!

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:39 pm
by robynfali
have uploaded it to my website


to my root weather folder, my realtime.txt file is here


http://www.h-i-r.org.uk/weather/realtime.txt

I have changed the location in your script, to this below, but get a blank page?

Code: Select all

$file_clientraw = file_get_contents("weather/realtime.txt"); // change this line if realtime.txt is at another location
$data_clientraw = explode(" ", $file_clientraw);


http://h-i-r.org.uk/weather/view-realtime.php

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:46 pm
by phtvs
I think you need to add this: ../ before: weather/realtime.txt

So that line must be:

../weather/realtime.txt

If that wont work you can also use this line:

http://www.h-i-r.org.uk/weather/realtime.txt


EDIT:
To test the script use your browser to go to the script like this:

http://h-i-r.org.uk/weather/view-realti ... ction=view

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:49 pm
by steve
The PHP file is already in the 'weather' directory, so presumably this would work:

$file_clientraw = file_get_contents("realtime.txt");

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:52 pm
by phtvs
steve wrote:The PHP file is already in the 'weather' directory, so presumably this would work:

$file_clientraw = file_get_contents("realtime.txt");

Of course...

Thanks for helping, Steve!

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:54 pm
by robynfali
tried both, no luck, strange this is, when you look at the page source for the .php page, it has no coding?

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:59 pm
by steve
Looks fine from here: http://h-i-r.org.uk/weather/view-realti ... ction=view
Mozilla Firefox_2011-01-10_12-57-44.png

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 12:59 pm
by phtvs
robynfali wrote:tried both, no luck, strange this is, when you look at the page source for the .php page, it has no coding?

Seems to me that it works perfect...

Follow this link:

http://h-i-r.org.uk/weather/view-realti ... ction=view

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 2:44 pm
by gemini06720
robynfali wrote:tried both, no luck, strange this is, when you look at the page source for the .php page, it has no coding?
Rob, if you try to look at a PHP script through your browser, you should/would see nothing of the code of the script ... because the script itself is not sent to your browser but processed by your Web server and only the results are sent to your browser... ;)

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 2:45 pm
by robynfali
didnt realise you needed the
?action=view
bit after, sorry

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 2:49 pm
by gemini06720
Theo, I have quickly looked at the code of your 'view-realtime.php' script... Once I tried it, I will probably come up with some suggestions, one of them being a check for the presence of the 'realtime.txt' before trying to read the file... ;)

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 3:41 pm
by phtvs
gemini06720 wrote:Theo, I have quickly looked at the code of your 'view-realtime.php' script... Once I tried it, I will probably come up with some suggestions, one of them being a check for the presence of the 'realtime.txt' before trying to read the file... ;)

Good idea. I was working on that part but got stuck..
Im just a beginner at php scripting ;-)

Sugestions are always welcome!!

So feel free to make the script better!

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 5:52 pm
by phtvs
Finaly got the filecheck function working...

The script checks if realtime.txt is there, if not then it displays a warning and exits from the script.

Done it the easy way, so if someone can do it better, please do!!

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 6:07 pm
by steve
Just a minor comment, if I may:

Code: Select all

$filename = "realtime.txt";
if (file_exists($filename)) {
//
// edit these lines when needed
//
$file_clientraw = file_get_contents("realtime.txt"); // change this line if realtime.txt is at another location
You have the realtime.txt file in twice; better to just have it once at the beginning, for the user to configure, and then use the same variable again later:

Code: Select all

$filename = "realtime.txt";  // change this line if realtime.txt is at another location

if (file_exists($filename)) {
$file_clientraw = file_get_contents($filename);

Re: Cumulus realtime.txt file reader

Posted: Mon 10 Jan 2011 6:19 pm
by phtvs
So true, Steve...

Thanks for the tip. I change that and post a new rar file with the correct php file in my first post.

EDIT: updated my first post with new rar file.