Weatherbug XML API script and templates

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

jpingle
Posts: 37
Joined: Mon May 09, 2005 4:08 pm

Post by jpingle »

I spoke too soon. I was getting NaN on one of the values, probably something I changed -- so I went back and removed the templates and graphs, then added them again.

When I did, the original problem came back:

Code: Select all

01/03/2008 03:30:01 PM - CMDPHP: Poller[0] Host[0] DS[997] WARNING: Result from CMD not valid.  Partial Result: 
01/03/2008 03:30:01 PM - CMDPHP: Poller[0] Host[0] DS[997] CMD: php /usr/local/share/cacti/scripts/wbugxml.php, output: U
01/03/2008 03:30:01 PM - CMDPHP: Poller[0] DEBUG: SQL Exec: "insert into poller_output (local_data_id, rrd_name, time, output) values (997, '', '2008-01-03 15:30:01', 'U')"
I'm sure there's something else I'm missing with the new script, since I have seen some output . I'm just not sure what I would have changed during the upgrade that may not have carried over when removing and re-adding the templates and graphs.
Just as a side: There's an updated script that copes with those changes; I'm using it successfully
Reinhard
I am aware, and I tried it, but for whatever reason it was reading the wrong values from the page. This morning, the temperature was 9 degrees F, but the graph in cacti showed 25 or so. I looked at the source of the page it was reading and the number it was recording was nowhere on the page. There were similar errors for most other values it was trying to scrape out of the page.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

jpingle wrote:
Just as a side: There's an updated script that copes with those changes; I'm using it successfully
Reinhard
I am aware, and I tried it, but for whatever reason it was reading the wrong values from the page. This morning, the temperature was 9 degrees F, but the graph in cacti showed 25 or so. I looked at the source of the page it was reading and the number it was recording was nowhere on the page. There were similar errors for most other values it was trying to scrape out of the page.
I suppose the new script used metric units. There must be a switch somewhere to reset to Fahrenheit and stuff
Reinhard
jpingle
Posts: 37
Joined: Mon May 09, 2005 4:08 pm

Post by jpingle »

I got the script working again, though I was bad and changed two things at once so without more testing tomorrow I'm not sure which fixed it - relaxing the permissions on the rrd file, or changing the script to end in .sh and starting it with #!/usr/local/bin/php.
I suppose the new script used metric units. There must be a switch somewhere to reset to Fahrenheit and stuff
Reinhard
It's possible that there was some internal conversion going on but I didn't see where it might have been happening. I much prefer to use the XML API and get the values directly rather than having to scrape the page for data, possibly inaccurately. It seems like the more correct way to do it, even if you do have to jump through some extra hoops (the API key) to get it working properly.
jpingle
Posts: 37
Joined: Mon May 09, 2005 4:08 pm

Post by jpingle »

I did a little more experimenting with the old script vs this API script. Here is what I found: The URL that was in the old script was wrong. And the URLs given in the updated thread were not working for me either. I tried a few different ways, but they all forwarded me back to the weatherbug site with a custom URL for the area I am in. I was using the observations from a school, not from an airport (small city, no airport with weather reporting).

For whatever reason, using the updated URL from the other thread, it was returning the weather observations at the Weatherbug HQ instead of for the area I had selected. It was ignoring the ID code and the Zip code, I tried both ways.

I finally managed to get the old script working (and I'll post a reply in that thread as to how) but I like the new way better, so I'll keep using it for the time being. Short version: They not only changed the URL, but also the ID code for the observation station.
urek
Posts: 1
Joined: Mon Nov 17, 2008 7:32 pm

Post by urek »

For anyone having a problem with the weird symbol's showing up for Dewpoint and FeelsLike temperatures, which causes them to report as 'nan':

Replace these lines:

Code: Select all

        $out_string .= "dewpoint:" . $stat->{'dew-point'} . " ";
        $out_string .= "feelslike:" . $stat->{'feels-like'} . " ";
With this:

Code: Select all

        $out_string .= "dewpoint:"    . substr($stat->{'dew-point'},0,2)     . " ";
        $out_string .= "feelslike:"   . substr($stat->{'feels-like'},0,2)    . " ";
Gunnar
Posts: 14
Joined: Wed Jun 24, 2009 10:38 am

Post by Gunnar »

TheWitness wrote:All,

Reviewing Mondo1287's script, I noted an issue relative to the outputing of the script results. The method chosen will cause problems with Cactid. Therefore, I have revised the code attached.

TheWitness
Hello.

I am still having the interrupted graph issue with this one. Can you tell me what code changes will fix this in the script? I compared your script with the original and see only that you took out unnecessary spaces..

Thanks for the help.
mschirrmeister
Posts: 1
Joined: Thu Aug 27, 2009 3:40 pm

Post by mschirrmeister »

Hi,

I have a problem with the wbugxml.php file in terms of geting back "metric" values.

The php script uses the URL,
http://XX.api.wxbug.net/getLiveWeather. ... ationID=XX

If I append to this URL the unittype=1 for metric values, I still get back non-metric values.

So I tried the URL,
http://XX.api.wxbug.net/getLiveWeatherR ... ationID=XX
which supports the unittype=1 option.

But it looks like something goes wrong with the parsing with this second URL. Each item comes back 4 times.
The output looks then like this.

Code: Select all

temp: humidity: dewpoint: feelslike: light: pressure: wind: gust: raintoday: rainmonth: rainyear: rainrate: rainratemax:temp: humidity: dewpoint: feelslike: light: pressure: wind: gust: raintoday: rainmonth: rainyear: rainrate: rainratemax:temp: humidity: dewpoint: feelslike: light: pressure: wind: gust: raintoday: rainmonth: rainyear: rainrate: rainratemax:temp:23.0 humidity:56 dewpoint:13.8888888888889 feelslike:23 light:0.0 pressure:1014.9 wind:9 gust:39 raintoday:0.00 rainmonth:0.00 rainyear:0.00 rainrate:0.00 rainratemax:0.00
Has anyone an idea?


Marco
unforgiven_soldier
Posts: 1
Joined: Tue Feb 01, 2011 1:59 am

Re: Weatherbug XML API script and templates

Post by unforgiven_soldier »

Gents, I have mod'd the wbugxml.php to the following (works like a charm)

Code: Select all

#!/usr/bin/php
<?php

$apicode   = "CHANGETHIS";
$stationid = "CHANGETHIS";
$zipcode   = "CHANGETHIS";

$url     = "http://" . $apicode . ".api.wxbug.net/getLiveweather.aspx?acode=" . $apicode . "&zipcode=" . $zipcode . "&StationID=" . $stationid;
$awsdata = file_get_contents($url);

if($awsdata == "Access Denied"){
        die('Access Denied to API resources');
}
$xml     = simplexml_load_string($awsdata);

$out_string = "";
foreach ($xml->children('http://www.aws.com/aws') as $stat) {
        $out_string .= "temp:" . $stat->temp . " ";
        $out_string .= "humidity:" . $stat->humidity . " ";
        $out_string .= "dewpoint:" . $stat->{'dew-point'} . " ";
        $out_string .= "feelslike:" . $stat->{'feels-like'} . " ";
        $out_string .= "light:" . $stat->light . " ";
        $out_string .= "pressure:" . $stat->pressure . " ";
        $out_string .= "wind:" . $stat->{'wind-speed'} . " ";
        $out_string .= "gust:" . $stat->{'gust-speed'} . " ";
        $out_string .= "raintoday:" . $stat->{'rain-today'} . " ";
        $out_string .= "rainmonth:" . $stat->{'rain-month'} . " ";
        $out_string .= "rainyear:" . $stat->{'rain-year'} . " ";
        $out_string .= "rainrate:" . $stat->{'rain-rate'} . " ";
        $out_string .= "rainratemax:" . $stat->{'rain-rate-max'} . " ";
}

echo $out_string;
?>

Please note that you need to issue a

Code: Select all

chmod +x wbugxml.php
Hope this solves future issues!
Y0d4
Posts: 7
Joined: Mon Sep 03, 2012 7:49 am

Re: Weatherbug XML API script and templates

Post by Y0d4 »

Hello, i just change with your update script and now i got next error (graph. don`t work)

# php wbugxml.php
PHP Parse error: syntax error, unexpected ',' in /usr/share/cacti/site/scripts/wbugxml.php on line 13
Y0d4
Posts: 7
Joined: Mon Sep 03, 2012 7:49 am

Re: Weatherbug XML API script and templates

Post by Y0d4 »

i am sorry, all is ok, it was wrong ID station :)
Y0d4
Posts: 7
Joined: Mon Sep 03, 2012 7:49 am

Re: Weatherbug XML API script and templates

Post by Y0d4 »

I am sorry, one more question. how to change to metric unit?

thank you.
Un4Seen
Posts: 8
Joined: Sat Dec 08, 2012 7:57 pm
Contact:

Re: Weatherbug XML API script and templates

Post by Un4Seen »

Hello!

I've updated the PHP script to work with metric units. I'm not a PHP programmer, so it might be a bit ugly, but it works. To change back to imperial units, just remove the end of the URL: . "&unittype=1".
Attachments
wbugxml.zip
(624 Bytes) Downloaded 121 times
Y0d4
Posts: 7
Joined: Mon Sep 03, 2012 7:49 am

Re: Weatherbug XML API script and templates

Post by Y0d4 »

Hello,

thank you for this, i was looking this solution.
I added ". "&unittype=1"" at the end of line, but on graph i still see Fahrenheit, not Celsius:
https://www.dropbox.com/s/0g80k2si4qbrp4i/temp.JPG

Did i need something more to change?


thank you.
Un4Seen
Posts: 8
Joined: Sat Dec 08, 2012 7:57 pm
Contact:

Re: Weatherbug XML API script and templates

Post by Un4Seen »

Adding "&unittype=1" to the end of the URL in the existing script does not work, I'm afraid. You need to use my script (attached in my previous post), which uses a different URL and adifferent XML parsing. The basic idea is that I had to hack the php script for it to work with metric units. You must replace your existing PHP script with mine (which can also work with imperial units if necessary).
Y0d4
Posts: 7
Joined: Mon Sep 03, 2012 7:49 am

Re: Weatherbug XML API script and templates

Post by Y0d4 »

ok, i change with your file, and rebuild poller cache, now he shows me ok on showing rows
https://www.dropbox.com/s/gym1bud209hl9d0/cacti1.JPG

but when i enter on temperature to see past, i got old:
https://www.dropbox.com/s/pwa6e0lb64yvyrr/cacti2.JPG

maybe need to clear rrd files? (which i don`t want if i don`t need :) )
Post Reply

Who is online

Users browsing this forum: haflinger and 0 guests