Restored Connection With shard7

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

Re: Restored Connection With shard7

Postby tim » Wed Jun 30, 2010 3:48 pm

I was watching this thread a while ago and have been using shard7's code.
viewtopic.php?f=16&t=369#p2432

I thought I would write and share my experience.

The code was working great and I thought my problems were gone. Then my router died, a totally unrelated event. I got a new router, an Apple Airport Extreme. I had been using WEP, but this new router does not support WEP, so now I am using WPA2. First thing I noticed was that CONNECTION_TIMEOUT no longer seemed long enough. I tried increasing it to about 65, but then found that the WiServer would not be re-inited. The code:
else if (millis() - connectTime > CONNECTION_TIMEOUT * 1000)
would never be true. Confusion. I changed the define to
#define CONNECTION_TIMEOUT (unsigned long)65000
and the line of code to
else if (millis() - connectTime > CONNECTION_TIMEOUT)
I also change the variable declaration of connectTime to
unsigned long connectTime = 0;

Which now seems to work. I can disconnect the AP for some time (minutes, hopefully later hours) and reconnect it and the WiServer will come back on line :-) The time out seems to need to be longer the weaker the wifi single is. 65000ms seems to work for the location where I want the WiShield to be.

I wish I could sound all smart and tell you why the two lines of code are not the same, but I can't.

I like the changes that shard7 made to WiServer. Even when the WiShield would lose connection the rest of the code worked just fine. I have just made the changes noted above, We will see in a day or so if this keeps working.

Tim
tim
 
Posts: 11
Joined: Sun Apr 11, 2010 1:13 pm

Re: Restored Connection With shard7

Postby GregEigsti » Thu Jul 01, 2010 12:27 am

Nice! Thanks for the great info!
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: Restored Connection With shard7

Postby shard7 » Sat Jul 03, 2010 5:51 am

Tim,

Thanks for posting your findings, that helps a lot!

The timeout value I originally chose was pretty much a random guess. It needs to be long enough to allow the connection to happen, but you don't want to wait too long before trying again. I think your value of 65 seconds seems fine. Maybe a nice round 60 seconds would work? Or better yet, I can make it 60 seconds by default by then add an API so you can set it to your exact liking from your sketch (and thus you don't have to modify the library). Something like: WiServer.setConnectTimeout(int seconds)

Anyone else have thoughts or experiences with this aspect of the changes?

Mark
shard7
 
Posts: 64
Joined: Wed May 06, 2009 11:30 am

Re: Restored Connection With shard7

Postby spidermonkey04 » Sat Jul 03, 2010 2:35 pm

A bit off topic, but I've been playing with the idea of adding the ability to use a precalculated PSK. This would drastically cut down the time needed to connect to a WPA/WPA2 AP. Since you have to recompile for a password change anyway, it wouldn't be too much more work to go to http://www.wireshark.org/tools/wpa-psk.html and precalculate the key instead of making the wifi module do it. Just an idea.

---Jared
spidermonkey04
 
Posts: 66
Joined: Thu Oct 29, 2009 6:45 pm

Re: Restored Connection With shard7

Postby aerodyno » Thu Sep 23, 2010 2:14 pm

Hey Shard7 and friends,

Thanks for all of your help here.

I'm trying out the code now -- a bit better than the Hruska solution that I've been using.

I made a few changes --

In WiShield.init() I threw in a "state=DISCONNECTED". Just so if I init later, it forces us back to the starting condition.

So in my code, I have a last ditch line which is "hey, if you haven't downloaded anything in 15 minutes, something's wrong. reset everything and reconnect!"

In this function I call WiServer.init() again, and set my three POSTrequest .active properties to false. That seems to be important, still.

I'll keep you posted!

Thanks again!

-s
aerodyno
 
Posts: 65
Joined: Tue Aug 04, 2009 8:42 pm

Re: Restored Connection With shard7

Postby aerodyno » Thu Sep 23, 2010 3:09 pm

So I had 6 wishields running overnight with this code, with connection timeout set at 59000 ms (I've noticed that the longest it ever takes to connect, even with WPA2, is about 45 seconds).

One of the wishields died -- I can't ping it, and the WiFi light is on. When I disconnect the router, the wifi light stays on. But the other 5 are going strong, which is awesome. I may try setting a slightly shorter connection timeout. Like 55 seconds.

What circumstances could create this case? Could it be a hardware issue?

-s
aerodyno
 
Posts: 65
Joined: Tue Aug 04, 2009 8:42 pm

Re: Restored Connection With shard7

Postby aerodyno » Tue Sep 28, 2010 11:19 am

As an update, my shields run fine for a few days, then today 4 of them dropped.

I have a timer that says, "hey you didn't see a download, call wishield.init() and restart the wifi" but for some reason, that doesn't seem to be working. The WiFi lights are ON on these shields, but they are not ping-able. What does this mean? I also noticed the board status LED (L)? Is off...
aerodyno
 
Posts: 65
Joined: Tue Aug 04, 2009 8:42 pm

Re: Restored Connection With shard7

Postby GregEigsti » Tue Sep 28, 2010 3:00 pm

What does this mean?

Would be interesting to see what kind of longevity/robustness that a WebServer (non WiShield) app has...

Thanks!
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: Restored Connection With shard7

Postby aerodyno » Wed Oct 20, 2010 1:26 pm

As an update, I now have some shields running for several days / weeks without dropping. I use a WATCHDOG TIMER on the atmega 328. If the Shield doesn't communicate for 15 minutes, start the watchdog timer, which forces a full reset of the Atmega 328.

Sadly, this works a lot of the time, but sometimes, the Shield gets stuck in a state that I believe still requires an actual power cycle to get it going again!

Is there some low level command to make the WiShield reset itself, just as I can reset the Arduino with a watchdog timer?

-aerodyno
aerodyno
 
Posts: 65
Joined: Tue Aug 04, 2009 8:42 pm

Re: Restored Connection With shard7

Postby spidermonkey04 » Wed Oct 20, 2010 4:09 pm

There sure is.
If I remember correctly, its in zg_init(). It'll hardware reset the zg2100 chip, clear any of its interrupts and wait until its completely reset.
---Jared
spidermonkey04
 
Posts: 66
Joined: Thu Oct 29, 2009 6:45 pm

PreviousNext

Return to WiServer

Who is online

Users browsing this forum: No registered users and 2 guests