Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: How to "run" a URL? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: January 06 2014 at 12:54 | IP Logged Quote GadgetGuy

I know there has to be a way, but haven't been able in the
doco or Forum to figure out how to open a URL from PH in
order to run a CGI command.

I am trying to control my Home Security system by
"running"...

http://192.168.1.81/2?A=3&p=1&X=1234

How does one do this?   


Edited by GadgetGuy - January 06 2014 at 12:54


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4399
Posted: January 06 2014 at 17:26 | IP Logged Quote dhoward

Ken,

You should be able to just use ph_geturl (or ph_geturl1). I pass parameters to these functions all the time.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: January 06 2014 at 19:16 | IP Logged Quote GadgetGuy

Didn't realize that CGI parameters could be passed this
way!

Now if I can get past the login/pw issue (not PH related)
with this URL, I'm looking forward to success here!   

Thanks Dave.
PS-the weather map seems to indicate you are a lot warmer
in FL than the -14 now in MI with a windchill below -40.

Ohh, dang. It's cold! Stay warm.

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: August 04 2014 at 13:54 | IP Logged Quote syonker

Hi Gang,

A little bit of an "Uh Oh" on this one. My goal is to
get precipitation total for the day from a Weather
Underground station that's nearby. The following line...

ph_geturl1( "http://www.wunderground.com/personal-
weather-station/dashboard?ID=KCOHIGHL5#history",1,20)


...when run with a "Set System" line (I've tried
LOCAL1 and LOCAL6 just for fun
) in a macro seems to
be sending in the "status" of the call as opposed to the
value of the HTML in the URL. This same line is used
with a different line above in the macro with success.
That line is as follows:

ph_geturl1( "http://mobile.wunderground.com/cgi-
bin/findweather/getForecast?
brand=mobile&query=80126",1,20)


For whatever reason the earlier call succeeds and the
latter is, in a word: "Wonky". Tried a Message Box to
see what was in LOCAL6 here and only half of the text
that reads "200 OK" can be seen with an OK button.

When running the call in the Formula Builder, the return
is evident and completely intact. I was wondering if
it's possible that I'm exceeding some sort of buffer
length and if so are there any suggestions on how to
handle that?

If we thing this is something else, or I have missed
something obvious (which is possible - I'm a little
brain-fried right now), please let me know.

Thanks in advance for any assistance offered.

-S

__________________
"I will consider myself having succeeded when my house becomes sentient and attempts to kill me."

><(((>`..`.><(((>.

`.. , . ><(((>`..`.><(((>
Back to Top View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: August 04 2014 at 14:54 | IP Logged Quote GadgetGuy

Snoker-

There is a string length limit on some of the string manipulation functions. Without checking further, I don't recall which, and thus if it may be a problem.

BUT, I was having similar issues in not being able to "see" everything that I fetched.

I solved it by first viewing "Page Source" in my browser and then scrapping that and pasting it into Word, where I could do a character count analysis to find the location of the string I was attempting to seek out.

I solved that issue using the following approach . . .



The red boxed function extracts the area of interest around your sought weather information. I left plenty of cushion +/- around the actual string.

This smaller sting can then be examined with User Messages or other tools, and may help give you some insight into what is happening.

Good luck

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4399
Posted: August 04 2014 at 20:46 | IP Logged Quote dhoward

S,

I tested your first formula and it appears to be working fine for me (there should really be no difference between the first and second formulas).

The ph_geturl1 function returns the header info (so you should see the 200 OK info as well as the rest of the headers) followed by the actual HTML data from the URL. This header info contains carriage return line feeds so may not display all the data but should still available via the regex functions.

Ken is correct that sometimes its best to pre-trim the returned HTML before processing with the ph_regexdiff1 function. Its more efficient (regex is kind of slow) and solves any limitations on variable length.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: August 05 2014 at 10:20 | IP Logged Quote syonker

Hooboy, I think my brain is broken. I am *sure* this is something with how they form the page, but it's making me spin in circles so thought I'd ping back.

I agree that it looks like everything here works the way it should. I have traversed the ENTIRE return using mid() 10,000 characters at a time (11K actually just to overlap).

The term I'm looking for is "precip_today". When right-clicking the page after loading the URL I mentioned above, and hitting "View Source", I saved off the result so I could search it. In Notepad++ sure enough, there it is, "precip_today" with a value of 0.0 (I live in a high-arid desert).

However several strange situations:

1) When using the following test it *always* fails and goes to "ERROR2":

if(posw( "[LOCAL6]", "precip_today") = 0, "ERROR2", "CONTINUE")

2) Also, when looking through the entire file manually, 11K chunk at a time using the command below (coupled with a Message Box) it is *never* to be found. When I look from 59,999 with an 11K character count in the mid() function, it is clear that either the page is built entirely dynamically and an entire section is missing (even though every time I "View Source" it's in roughly the same spot of 71,000 and change) or there is something entirely weird going on that I'm totally missing.

mid(ph_getvar_s(1,6),59999,15000)

Here is the whole section of the macro if that's helpful...



Edited by syonker - August 05 2014 at 10:24


__________________
"I will consider myself having succeeded when my house becomes sentient and attempts to kill me."

><(((>`..`.><(((>.

`.. , . ><(((>`..`.><(((>
Back to Top View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: August 05 2014 at 10:44 | IP Logged Quote GadgetGuy

syonker-

I had similar issues in my initial Get Weather attempts. Dave got me straightened out by recommending that instead of using the direct [LOCAL6] value as you have...

if(posw( "[LOCAL6]", "precip_today") = 0, "ERROR2", "CONTINUE")

That the ph_getvar_s(1,6) approach be taken instead.

The use if direct LOCAL/TEMP variables in a string formula can often lead to unexpected issues as the data conversion from number/string values is not always what you might expect.

Try this formula instead and see what happens...

if(posw( ph_getvar_s(1,6), "precip_today") = 0, "ERROR2", "CONTINUE")


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
syonker
Senior Member
Senior Member
Avatar

Joined: March 06 2009
Location: United States
Online Status: Offline
Posts: 212
Posted: August 05 2014 at 22:26 | IP Logged Quote syonker

Hi Ken and Dave,

No matter how many times I tried to solve this with the website to the local weather station it just did NOT parse right...and I don't think it's anything wrong with PowerHome - I think it's in how they dynamically build the website.

So decided to look into alternative options and boy did I inadvertently stumble on a winner while finding a new way to solve this.

Weather Underground has a free "developer API" you can sign up for that will VERY quickly return a customized XML-formatted document with only the raw information I needed (including full compliment of weather data combined with precipitation over time). You have to sign up for a free API key (be sure to pick the free option which is the developer/500 call-per-day/10 call-per-minute option - any larger volumes they sensibly want you to pay for). You simply register a free account with them. They send a confirmation e-mail for the account creation, and once you're in go through their "cart" (as mentioned previously at no charge to you if you pick the correct option) and check out. You are then issued an unlimited call API key (keep this tight for obvious reasons).

The documentation is fairly straight up. You can call by LAT/LON, city location, or look up a specific station and call by that ID (this is what I did as I know of a school-sponsored and maintained station about 1000 feet away. Here is an example call to the site using their demo API key that goes after a specific weather station:

ph_geturl1( "http://api.wunderground.com/api/6f4c56e1c72e7c82/geolookup/ conditions/q/pws:KCOHIGHL5.json",1,20)

...and here is an example of how to call out to a city location instead:

ph_geturl1( "http://api.wunderground.com/api/6f4c56e1c72e7c82/conditions /q/CA/San_Francisco.json",1,20)

NOTE: You have to put your own API key in where theirs is used here (I'm sure they cycle them so probably disable these on a frequent basis - these may not work directly without inserting your own key). Also, if you extract the HTML here it *will* run, but you have to open the result in something like NotePad++ to see it...and it's AWESOME (excerpt below):

     "local_time_rfc822":"Tue, 05 Aug 2014 19:52:10 -0600",
     "local_epoch":"1407289930",
     "local_tz_short":"MDT",
       "local_tz_long":"A merica /Denve r",
     "local_tz_offset":"-0600",
     "weather":"Clear",
     "temperature_string":"69.5 F (20.8 C)",
     "temp_f":69.5,
     "temp_c":20.8,
     "relative_humidity":"57%",
     "wind_string":"From the West at 1.2 MPH Gusting to 3.0 MPH",
     "wind_dir":"West",
     "wind_degrees":270,
     "wind_mph":1.2,
     "wind_gust_mph":"3.0",
     "wind_kph":1.9,
     "wind_gust_kph":"4.8",
     "pressure_mb":"1015",
     "pressure_in":"29.97",
     "pressure_trend":"+",
     "dewpoint_string":"54 F (12 C)",
     "dewpoint_f":54,
     "dewpoint_c":12,
     "heat_index_string":"NA",
     "heat_index_f":"NA",
     "heat_index_c":"NA",
     "windchill_string":"NA",
     "windchill_f":"NA",
     "windchill_c":"NA",
     "feelslike_string":"69.5 F (20.8 C)",
     "feelslike_f":"69.5",
     "feelslike_c":"20.8",
     "visibility_mi":"10.0",
     "visibility_km":"16.1",
     "solarradiation":"--",
       "UV":"1","precip_1 hr_str ing":" 0.00 in ( 0 mm)",
     "precip_1hr_in":"0.00",
     "precip_1hr_metric":" 0",
     "precip_today_string":"0.00 in (0 mm)",
     "precip_today_in":"0.00",
     "precip_today_metric":"0",

It returns a *wonderful* packet of information that is small and easily-parsed and include just about everything weather I need for PowerHome.

The URL for the API is: http://www.wunderground.com/weather/api

Pick the "SIGN UP!" option first, then do the key creation (otherwise it makes you create the key twice - I found this out the hard way).

Changing out my entire "GET_WEATHER()" macro with the data here straight away. Here is the beginning of the result - it's cleaner, faster, and works perfectly:



Cheers,

-S

Edited by syonker - August 05 2014 at 22:28


__________________
"I will consider myself having succeeded when my house becomes sentient and attempts to kill me."

><(((>`..`.><(((>.

`.. , . ><(((>`..`.><(((>
Back to Top View syonker's Profile Search for other posts by syonker Visit syonker's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: August 06 2014 at 07:47 | IP Logged Quote GadgetGuy

syonker-

GREAT find.

I was surprised at all the issues you were encountering, as I thought my GET-WEATHER macro was using Weather Underground too.

It turns out, when I looked this morning, that I am using a different site . . .

ph_geturl( "www.weatherforyou.com/reports/index.php?forecast=zandh&pand s=48118&Submit=Get+Weather")

which has been stable for several years. My prior site kept redesigning itself and thus corrupting my string rettrival efforts. :-(

Your solution looks like a nice stable, and easy to parse, approach that should make things much easier for anyone attempting to fetch local weather data.

Good job.


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4399
Posted: August 08 2014 at 18:18 | IP Logged Quote dhoward

S,

Excellent find. I'll have to add a note to work up a sample using this with the URL Scraper plugin.

Thanks for posting this.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: November 27 2014 at 10:15 | IP Logged Quote GadgetGuy

dhoward wrote:
S,

Excellent find. I'll have to add a note to work up a sample using this with the URL Scraper plugin.

Thanks for posting this.

Dave.


Dave-As soon as I can get this going I will add it to the URLScraper Help file. Hopefully I can achieve that before you release PH 2.1.5b   

BTW - Snoker EXCELLENT FIND!! Way to go!

Edited by GadgetGuy - November 27 2014 at 10:16


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: November 27 2014 at 10:53 | IP Logged Quote GadgetGuy

Dave - Trying to get the URLScraper to extract data using the Weather Underground API, but with no success.

To start, just trying to pull one thing (temperature) but I never get a trigger response, nor do I get a response on the Command 256 Scraper error trigger.

Not sure if I am doing something wrong or if the data returned by the API is throwing the scraper for a loop.

Here is what I have so far, with the scrape .ini on the left, and what I think the the data should look like on the lower right (highlighted in yellow).

Any ideas?


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 896
Posted: November 27 2014 at 11:42 | IP Logged Quote GadgetGuy

Got it solved.

The documentation was not clear and I will fix the Help file for this plugin before 2.1.5b is released.

The problem was in the way I had the Triggers set up. When the scrapecount is >1 then the trigger "Trigger ID Number" must also be adjusted to match each URL group. Since I had two URL Groups defined, I needed to use "Command 2" for trigger ID # and NOT Command 1 as I had.

I'm getting data now!    

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum