Need help with multiple synchronous get() code

Discussions related to the WiServer add-on code for WiShield. WiServer is a friendly, easy-to-use front end for webserver and webclient usages.

Moderator: shard7

Need help with multiple synchronous get() code

Postby shobley » Thu Jun 10, 2010 8:08 pm

Hi,

I'm currently porting the WorldMoodLamp code recently posted on the Instructables website.

http://www.instructables.com/id/Twitter ... -in-a-Box/

This code works with the WiFly shield, and as far as I can tell, passes in an HTMLParser object into the get call. The get completes synchronously, and the parsed values are read back from the HTMLParser before moving onto the next get.

WiServer seems to be much more asynchronous - is there a simple way to change the flow to operate more like this? :

1. Perform get request on twitter_search_url
2. Send each packet of response data to parser
3. Once request completed extract values from parser
4. Move on to next twitter_search_url, goto 1.
5. Once all 7 searches complete, update mood light

This is more synchronous, step 4 is only run once steps 1-3 have completed.

Thanks in advance.

Steve
Last edited by shobley on Fri Jun 11, 2010 7:14 am, edited 1 time in total.
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 5
Joined: Thu Jun 10, 2010 7:57 pm

Re: Need help with multiple synchronous get() code

Postby GregEigsti » Thu Jun 10, 2010 11:41 pm

Have you looked at the WebClient or TCP socket examples? What you want to do is certainly possible with WiServer or with the samples mentioned but you are going to have to "make it work" as there is no pre-canned example to do what you want. Any of these examples are certainly capable of doing what you want (or at least providing a starting point) but it won't be for free ;) WiServer will certainly abstract away a bunch of the "low level" work but its going to be up to you to put the pieces together.

Kind of sounds like you have found some sample code and are trying to munge it to work with WiServer?

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Need help with multiple synchronous get() code

Postby shobley » Fri Jun 11, 2010 5:12 am

Munge??

I've never been so insulted...
:mrgreen:

No you are quite right, I'm trying to create a drop in replacement for the WiFly library in an existing project.

I was about to edit my initial posting and ask "is there not an API reference for the library?" when I found it.

The .IsActive() call was what I needed, I just used this to control a while loop with the .server_task() method and now I could operate successfully on the "gets" after they were done.

Code: Select all
bool GetHttpWebRequest(char* s)
{
  // Create the webrequest
  GETrequest getTweets(twitter_ip, 80, "www.twitter.com", s);
  getTweets.setReturnFunc(printData);
 
  getTweets.submit();
 
  int count = 0;
 
  // Process
  while(getTweets.isActive())
  {
    WiServer.server_task();
    delay(10);
    count++;
   
    // Timeout = 20 seconds approx
    if (count > 2000)
       return false;
  }
 
  return true;
}



Steve
Last edited by shobley on Fri Jun 11, 2010 7:14 am, edited 1 time in total.
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 5
Joined: Thu Jun 10, 2010 7:57 pm

Re: Need help with multiple synchronous get() code

Postby shobley » Fri Jun 11, 2010 7:02 am

Here's a video of the port...

http://www.youtube.com/watch?v=3q4j63AStnY

It's doing the Twitter stuff just fine, but for some reason the LED is getting stuck on blue most of the time, need to check the wiring!
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 5
Joined: Thu Jun 10, 2010 7:57 pm

Re: Need help with multiple synchronous get() code

Postby GregEigsti » Fri Jun 11, 2010 9:34 am

Cool, sounds like you are on your way. Just make sure that you call "WiServer.server_task();" often/quickly as the WiShield needs to be serviced in order to stay alive - but it looks like you are doing that.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Need help with multiple synchronous get() code

Postby shobley » Fri Jun 11, 2010 6:10 pm

I only got the shield yesterday, and this has been a good introduction to how it all works.

One thing I've noticed, sometimes it seems to drop the connection for no reason.
I have a "wait" loop that calls the server_task function every 6 seconds - is this enough to keep it awake?

Is there no rapid sleep/wake mode in 80211b? If the shield sleeps do I have to call .init again?

Steve
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 5
Joined: Thu Jun 10, 2010 7:57 pm

Re: Need help with multiple synchronous get() code

Postby GregEigsti » Fri Jun 11, 2010 6:48 pm

Six seconds should be quick enough but then again maybe not; try servicing the WiShield more often to see if that helps. The problem commonly seen on the forums are folks who don't service it for around a minute - not sure why a minute is what everyone picks... My best advice is to service the WiShield as often as possible - there is a lot going on in the background and it needs processor cycles to stay on the WiFi network.

If the shield sleeps do I have to call .init again?

Not sure what you mean by "if the shield sleeps" but yes - if you starve it and it falls off of the network then calling .init again should get you going. Many folks would like to be able to put the WiShield to sleep and have it wake up occasionally to do something - this is not really a reality for WiFi as the ZeroG module needs to do a lot in the background just to stay on the network. That said I did notice some "sleep" related stuff, which appears to be disabled, in the ZeroG driver (g2100.c/h). I have not had a need to play with sleeping the WiShield so I have never gone any further than just noticing it ;)

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Need help with multiple synchronous get() code

Postby shard7 » Sat Jun 12, 2010 4:55 am

I encourage your to try the experimental changes to WiServer posted here (just replace WiServer.cpp and WiServer.h with the ones provided): http://asynclabs.com/forums/viewtopic.php?f=16&t=369#p2432

These changes are designed to make WiServer more resilient against lost connections, but I think it might also be useful for your situation.
shard7
 
Posts: 64
Joined: Wed May 06, 2009 11:30 am

Re: Need help with multiple synchronous get() code

Postby shobley » Sun Jun 13, 2010 4:37 am

I tried the new WiServer class, but I couldn't get it to connect.

I could see the extended logging, but I kept getting "connection failed" and when I checked with my router, no wireless connections had been issued.
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 5
Joined: Thu Jun 10, 2010 7:57 pm

Re: Need help with multiple synchronous get() code

Postby shard7 » Sun Jun 13, 2010 7:07 am

Did you try calling WiServer.checkConnection(-1) first? This call will block and wait until a connection is made, so that way you can be sure of a connection before you try to do things with it.
shard7
 
Posts: 64
Joined: Wed May 06, 2009 11:30 am


Return to WiServer

Who is online

Users browsing this forum: No registered users and 1 guest