Sample Entry - Get worldwide weather data into your strategy


Hi OptoFans,

Here’s a subroutine that might be helpful to you if you want your strategy to have current weather information, from nearly anywhere on the planet. This could be displayed in PAC Display or used in logic (for example when deciding to turn on sprinklers for the lawn or not).

This weather-grabbing example requires 9.1 or newer PAC Control and firmware (uses new-in-9.1 HTTP commands).

Here’s how to use it:

Download the attached .zip file and extract the contents to a known location.

Double-click in your strategy tree on “Subroutines Included” and browse to the GetWeatherData.isb file included in the attached zip.

Find a “Station ID” in the location of interest by visiting Weather Underground here:

For example, the Station ID for one weather station here in Temecula is “KCATEMEC4” (Roripaugh Hills station).

Your call to the new command/subroutine will look something like this:

And the data returned in the string table you pass should look something like this:

What you’re seeing here is:
[0] = location info
[1] = temperature (degrees F)
[2] = relative_humidity
[3] = wind direction
[4] = wind speed (mph)
[5] = pressure in inches
[6] = precipitation today (inches)


See comments in the subroutine itself for ways you might modify this to better suit your needs.

Code on.


P.S. (7-31-2012) This newer version (attached v1.2) includes the fix I describe in a later post, and more error reporting. (5.21 KB)

Greatest Hits - and mini-lessons

Having trouble openning zip file??


I got that zip to Tom, anyone else having trouble w/zip attachments in OptoForums? If so, what browser are you using?


I am only able to retrieve the first field (location info). Any suggestion what I should check for or what I am doing wrong?



Hmm, not sure. Here’s a couple of questions for you:

  1. Does it work w/the station ID I gave as an example? (KCATEMEC4)

  2. What station ID were you using? (I’ll try it here and see if I see anything different.)

  3. Are you getting something non-zero back from the “Sub Status” parameter? If so, what did you get?



I get -20 in the “Sub Status” parameter. What does that mean?



VThomas: Thanks for trying this out. The -20 = “Device busy. May be in use by another user or another application.” Could the that weather server/station is busy? Can you try hitting it directly from a browser? For example, this link will show you the XML the subroutine is parsing one of the Temecula stations I give in the example. You can change the last piece of the URL to match the station you’re interested in:

Tim: I just found a little bug that could chop off data like you mention for certain weather stations. KCATEMEC4 wasn’t one of them – I apologize for missing this! I’ll share an update shortly…


Hi Tim,
Sorry for the trouble, thanks for trying this. I think I have a fix:

In Block 5, the yellow one called “Create temp file to store receive data”:
Line 11:

nCommStatus = TransmitStrTable(-1, 0, stDstStrTblBody, chTempFile);

Should be replaced with:

nIndex = 0;
while ( (GetStringLength(stDstStrTblBody[nIndex]) > 0) and
    (nIndex < GetLengthOfTable(stDstStrTblBody)) and 
    (nCommStatus == 0) )// loop while something in the table to write
  nCommStatus = TransmitString(stDstStrTblBody[nIndex],chTempFile);
  nIndex = nIndex + 1;

Could you let me know if that fixes it for you?


I can hit it directly with no problem. Its any station that I try, even Temecula’s.


What firmware version & hardware are you using?


OptoMary: All is working now and I did not do any changes. When I had the problem, it was doing it in all (5) stations I tried. This is very helpfull for our application because our system in affected by barometric pressure, now I can make minor adjustments accordingly.

Thank You.


Hi Tim,

Excellent! I’m glad it’s working and helpful for you. I’d recommend changing that one line anyway (the TransmitStrTable becomes multiple calls to TransmitString) because that subtle bug could come and go or not depending on, well, the weather!

I’m thinking I’ll write up a longer explanation of what’s going on here since the overall technique of using the HttpGet call then parsing what’s returned could be useful more generally for other information found out the web!



Fantastic. I can get the weather info from any station.


[INDENT]Try using IE9 (or using some other browser like Firefox). Were you using Internet Explorer version 8 when you had this trouble? That seems to be he common thread for those who’ve had trouble downloading/opening the attached zip archives.
-OptoMary [/INDENT]


Hello I am trying to get this to work for me but am getting an error in PAC Control when I run the subroutine.
The description of the error is GetWeatherData subroutine: Error calling HttpGet, returned: 0, HttpStatus: 403.
I’m pretty sure this is due to my proxy server but am not sure on how to get the subroutine to authenticate with it. Is there a way to write a script to authenticate with a proxy automatically before trying to get the weather data?


Hi All,

Currently there’s an issue running the Http commands w/SoftPAC & PAC Sim (possibly other PACs, depending on the circumstances).

Here’s another way of doing something very similar:

Happy Surfing!


Hi OptoMary, I keep getting an “error -50 HttpStatus:0” Any Ideas what I am doing wrong?


Hi insmike5,

Welcome to the OptoForums! For those HTTP commands I use in the sub, and just pass back, (from the command reference):[INDENT] -50 = Open connection timeout. Could not establish connection within the timeout period. Make sure that the controller is configured with a DNS and Gateway for the network.
[/INDENT]Do you have your DNS/Gateway set up on the PAC? (User PAC Manager to check/set those values.)

If you really have hit the timeout value (more likely if you have a very remote connection, like through a satellite) you might want to use this method of grabbing web server info, which gives you more control over the communication, including the timeout.



I am having the same trouble. Did you get a resolution for this? When I use my local weather station, it fills only the top line. When I use the KCATEMEC4 I get the location info only as well.


What version of firmware do you have? There’s a bug in R9.4a which will break the response-parsing part of that logic…