yahoo weather data event question...
vegastech
Posts: 369
I have my code working to parse data from yahoo's weather api site with static zip codes, and everything works great. I am now trying to use the keypad built into my 700vi to specify a zip code not already listed. I have everything working, except when I get to the actual data event handler for the newly-entered zip code. I have the following line, but it doesn't seem to return a result:
my prior lines of code work fine:
Can someone help me get a handle on what I need to format differently? I am using the variable sKeypad to hold the 5 digit zip code for the send_string. Thanks.
SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=',sKeypad,' HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
my prior lines of code work fine:
DATA_EVENT[dvIPWeather] //data event to query yahoo weather { ONLINE: { SWITCH(nZipCode) { CASE 1: { SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=89131 HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10" } CASE 2: { SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=91007 HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10" }
Can someone help me get a handle on what I need to format differently? I am using the variable sKeypad to hold the 5 digit zip code for the send_string. Thanks.
0
Comments
If the string of sKeypad is from a panel keypad (string from panel e.g. AKEYP-98765), did you have removed also the '-' (in DATA_EVENT..STRING from Panel, REMOVE_STRING(DATA.TEXT,"'-'",1))?
It's still a little buggy as the sleep timer was there first and I'm trying to use the keypad for multiple things at this point, but I haven't had a chance to work thru the various bugs. I just want to see how I can make a dynamic zip code work at this point.
When using sKeypad it looks like there is no space. Maybe that's why you get no result.
Never mind. I misread your code and I see now that you did include the space.
I also notice you trap the zipcode in an integer at the data event. There could also be a problem with that in that there are zipcodes with a zero in the beginning. If you left the zipcode trap variable a string you could avoid this problem.
Either way, I think I'd go ahead and trap the zipcode at the data event and then use that instead of the keypad buffer in the send_string.
If you were planning on using case 2: to fire the customer specified zip, the code posted still has a hard-coded zip. I don't know if that was intentional or not.
And because it is Integer, you easily can reformat it to an always 5-char string with the FORMAT command
Another way may be to redesign the panel a little, by using a keypad popup from the panel's system page template instead of the firmware keypad..
There you can now change the prefix of the textfield name (in general properties) from KEYP- to e.g. ZIP- . The keypad is now a popup, full functioning, and if the zip is typed there (e.g. 12345), you get a string from the panel 'ZIP-12345'
In the data event that you say is working, you have a Switch/Case, but I don't see where nZipcode becomes a 1, or a 2. If the zipcode is set as ATOI of a zipcode entry then it would be some 5 digit number e.g. 89131. The switch case shouldn't work, unless you have a default case underneath it all, in which case only the default case will fire.
SWITCH(nZipcode)
{
Case 1: ...
Case 2:...
}
Secondly, are you sure the sKeypad variable is showing the new zipcode you entered? You're using a Get_last in a data_event that just doesn't look right.
nSourceNum = GET_LAST(nKeypadSource) should evaluate to 0 as far as I can tell.
EDIT: Just realized nKeypadSource is probably a device array even though you prefixed it with an "n" which is usually used to denote an integer.
--John
to see what's really firing out.
Also, I would monitor the incoming buffer to see what's actually coming back from the site when that string is sent, nZipcode, and sKeypad to see if they're really the zipcode, and nSourceNum to see if it's really evaluating to 2 during a zipcode change.
--John
I added a 6th variable number to allow for the dynamically-changed zip code: The reason I was using the touchpanel-generated keypad was for 2 reasons: 1) it was easier than creating a 2nd, and 2), I want to use the keypad for multiple things, in this case a sleep timer custom entry as well as the zip code custom entry. I figured if I can determine how to do this with a single, generic keypad, it would aid in the further development of my netlinx coding skills. I have used diagnostics to monitor the result coming from the keypad, as well as the remove_string functionality: It places keyp-(add zipcode here) into the buffer, and then immediately strips it out, leaving only the zip code. Is it possible that the data event is trying to add the entire string, keyp-89131 into the http address before stripping the characters? How can I monitor the string it actually sent out?
glad yoiu got it figured out. It always seems to be the little things we overlook, doesn't it?