dj0tt / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

When wifi shield goes out of network range for a period of time, the tcpServer dies and does not respawn. #1086

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use any of the example sketches that instantiate the WiFiServer that come 
with the WiFi shield and load it up. ie. WiFiChatServer
2. Take your arduino+wifi shield out of wifi range and leave it there for a few 
minutes.
3. Take it back in to wifi range and it will be pingable, you'll be able to 
open a socket to the server, but it will just hang there. You can observe the 
TCP packets bouncing back and forth and eventually the wifishield disconnects 
you.

You should expect that when the wifi server is back in range, it will continue 
to serve new/old established connections.

I did some very superficial debugging and if you output server.status() you'll 
notice that at some point it returns 0, instead of 1. This is when you know 
it's dead. I've tried to add code that runs another server.begin(), to no 
avail. I've even added a new function to restart the server. Again, to no 
avail. I've yet to dig deeper.

I'm using the Arduino UNO + Arduino Wifi Shield, using 1.0.1 of the IDE in OS X 
Mountain Lion.

This function does not restart the server as I would expect when it dies, i've 
yet to debug why:
void WiFiServer::restart()
{
  uint8_t _sock = WiFiClass::getSocket();
  ServerDrv::startServer(_port, _sock);
}

Original issue reported on code.google.com by k...@vmfarms.com on 29 Oct 2012 at 12:03

GoogleCodeExporter commented 9 years ago
Additional information - If you lose connectivity by restarting the router and 
it re-establishes within a small amount of time (within 10-15 seconds), the 
server goes from 0 status to 1 and everything returns to normal. I'm trying to 
determine the condition or amount of time that passes before it can no longer 
restart the server more accurately. However,

I commented out:

            //server not in listen state, restart it
            if ((_ser_status == 0)&&(cycle_server_down++ > TH_SERVER_DOWN))
            {
              ServerDrv::startServer(_port, sock);
              cycle_server_down = 0;
            }

in "WiFiClient WiFiServer::available(byte* status)" and if you lose 
connectivity for the short duration scenario, it no longer restarts the server 
and the server remains dead.

Original comment by k...@vmfarms.com on 29 Oct 2012 at 1:43

GoogleCodeExporter commented 9 years ago
Please close this issue. The WiFi shield successfully disconnects and 
reconnects and brings the server along with it.

I did some thorough debugging today and the issue is attributed to the server 
having a stale client connection open after the arduino+wifi shield goes out of 
range and the client disconnects from it.  If there is no timeout written in to 
the server and the client never gets stop() called on it, it will prevent 
future client connections from happening. I will open up a separate issue for 
the multiple connection issue.

Original comment by k...@vmfarms.com on 30 Oct 2012 at 1:48