Home AMX User Forum AMX General Discussion

yahoo weather data event question...

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:
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.

Comments

  • Syntax seems to be ok, so what does sKeypad exactly containing (debug variable)? Does it have 5 digits?

    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))?
  • vegastechvegastech Posts: 369
    Yes, it has just the 5 digit zip code. Here is the data event, which I am also using for a sleep timer keypad entry (which works successfully):
    DATA_EVENT[dvCV7Tp] //sleep timer keypad entries, zip code lookup
    {
    STRING:
    	{
    		sKeypad = DATA.TEXT
    		
    			
    			IF (FIND_STRING(sKeypad,'KEYP-',1))
    				{
    					REMOVE_STRING (sKeypad, 'KEYP-',1)
    					//WAIT 50 'yeah'
    					nSourceNum = GET_LAST(nKeypadSource)
    					{
    						IF (nSourceNum=2)
    						{
    							nZipcode = ATOI(sKeypad)
    							
    						}
    						ELSE
    						{
    							nsleep = ATOI(sKeypad)
    							nsleep = nsleep*60
    					
    							SEND_COMMAND dvCV7Tp, "'^TXT-10,0,',nSleep"
    							TimeArray[1] = 1000
    							TIMELINE_CREATE(MBedSleep, TimeArray, 1,TIMELINE_ABSOLUTE,TIMELINE_REPEAT)
    						}
    						
    					}
    				
    				}
    

    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 you are sending the URL's without the variable and just typing in the zip you have a space between the zip and the rest of the string.

    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.
  • ericmedleyericmedley Posts: 4,177
    It's a little hard to tell what's going on with the code we have here. For example, what is inititating the code to start the conversation with the web server? With what you have shown, it seems possilbe that the variable holding the data needed for the zipcode could be changed before you get around to starting the web conversation. any string communication from the touch panel will blow out the data you need for the zipcode.
    DATA_EVENT[dvCV7Tp] //sleep timer keypad entries, zip code lookup
    {
    STRING:
    	{
    		sKeypad = DATA.TEXT
    

    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.
  • I also would use the nZipcode in the GET string instead of sKeypad.
    And because it is Integer, you easily can reformat it to an always 5-char string with the FORMAT command
    SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=',FORMAT('%05d',nZipcode),' HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    

    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'
  • A few things that I see...

    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
  • A few things that may help you to diagnose it are to add a few send_string 0's in there like so:
    SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=',sKeypad,' HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    SEND_STRING 0, "'GET http://weather.yahooapis.com/forecastrss?p=',sKeypad,' HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    
    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
  • vegastechvegastech Posts: 369
    For further clarification, I am using nZipcode to determine which button press is being selected in my weather page. It changes here, which i realize now I should have included originally:
    BUTTON_EVENT[dvCV7Tp,100]  //Weather Preset 1
    BUTTON_EVENT[dvCV7Tp,101]
    BUTTON_EVENT[dvCV7Tp,102]
    BUTTON_EVENT[dvCV7Tp,103]
    BUTTON_EVENT[dvCV7Tp,104]
    {                            
    	PUSH:
    	{
    		nZipCode = BUTTON.INPUT.CHANNEL-99
    		fcnWeather()
    	}
    }
    
    So nZipcode switches between 1 and 5. Each of the 5 presets has a specific zip code hard-coded into the netlinx code:
    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"
    				}
    			CASE 3:
    				{
    				SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=91775 HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    				}
    			CASE 4:
    			{
    			SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=USNV0040 HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    			}
    			CASE 5:
    			{
    			SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=USNY0176 HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    			}
    			
    		
    	}
    

    I added a 6th variable number to allow for the dynamically-changed zip code:
    CASE 6:
    			{
    			SEND_STRING dvIPWeather, "'GET http://weather.yahooapis.com/forecastrss?p=',sKeypad,' HTTP/1.0',13,10, 'Connection: Close', 13, 10, 13, 10"
    			}
    		}
    
    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?
  • vegastechvegastech Posts: 369
    I think the get_last is the source of my problem - can someone help me out with my usage? I am trying to set it up so that based on my source button selection (sleep timer OR weather page), I can use the get_last to determine which of those two buttons was selected, and as a result, run the appropriate code. I have created an integer array:
    INTEGER nKeypadSource[] = {505,55}
    
    this is to signify the two source selection buttons, 505 and 55, which are the sleep timer and weather buttons. As previously noted, it indeed does return a result of 0. I think I'm just using it wrong. the help files don't exactly help me to work it out, unfortunately. Thanks.
  • vegastechvegastech Posts: 369
    Ok, definitely NOT the get_last..ultimately it was a problem of a much more primitive nature...it helps when I actually decide to run the function and place all items in the proper order. (cart before the horse-type stuff...)you know, when you are relying on an integer to be above zero to execute a call, but that execution didn't actually happen yet?
  • ericmedleyericmedley Posts: 4,177
    vegastech wrote: »
    Ok, definitely NOT the get_last..ultimately it was a problem of a much more primitive nature...it helps when I actually decide to run the function and place all items in the proper order. (cart before the horse-type stuff...)you know, when you are relying on an integer to be above zero to execute a call, but that execution didn't actually happen yet?
    Well, alls well that ends well...
    glad yoiu got it figured out. It always seems to be the little things we overlook, doesn't it?
Sign In or Register to comment.