After a failed client.connect() and issuing a client.stop() the socket remains open. With each additional failed client.connect another socket is left open until complete failure of communication. This program polls a controller every 3 seconds and displays the data on the serial port and shows socket status. For the first 40 minutes everything is fine, then a failure and socket left open. At 5 hours another failure occurs and total ethernet communication failure. Below is the code and excerpts from the serial log.
Any suggestions would be appreciated.
void loop()
{
//Serial Print Up time
Serial.print("Uptime: ");
Serial.print(millis() / 60000);
Serial.println(" Mins.");
Serial.println();
//Select IP address for the appropriate controller
int connectionStatus = client.connect(HouseController, 80);
Serial.println("Connecting To House Controller.");
Serial.println();
//Close connection if a connection failure occurs
if (connectionStatus < 1)
{
client.stop();
Serial.println("*************************************************");
Serial.println("Stopping Client after initial connection failure.");
}
//Show Socket Status On Serial Monitor
ShowSockStatus();
//If connection successful to controller request JSON Data
if (connectionStatus == 1)
{
// Make a HTTP request:
client.println("GET /status.json HTTP/1.1");
client.println("Connection: close");
client.println();
}
while (client.connected())
{
while(client.available())
{
char c = client.read();
Serial.print(c);
}
}
Serial.println();
Serial.println();
//Flush Remaining Data In Ethernet Controller
client.flush(); //Clear Data Buffer In Ethernet Controller
client.stop(); //Close Communication With Irrigation Controller
delay(3000);
}
void ShowSockStatus()
{
Serial.println();
for (int i = 0; i < MAX_SOCK_NUM; i++) {
Serial.print(F("Socket#"));
Serial.print(i);
uint8_t s = W5100.readSnSR(i);
socketStat = s;
- Serial.print(F(":0x"));*
- Serial.print(s,16);*
- Serial.print(F(" "));*
- Serial.print(W5100.readSnPORT(i));*
- Serial.print(F(" D:"));*
- uint8_t dip[4];*
- W5100.readSnDIPR(i, dip);*
- for (int j=0; j<4; j++) {*
- Serial.print(dip[j],10);*
- if (j<3) Serial.print(".");*
- }*
- Serial.print(F("("));*
- Serial.print(W5100.readSnDPORT(i));*
- Serial.println(F(")"));*
} - Serial.println();*
}
Connecting To House Controller.
*************************************************
Stopping Client after initial connection failure.
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x15 1814 D:192.168.0.102(80)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
Uptime: 41 Mins.
Connecting To House Controller.
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x17 1814 D:192.168.0.102(80)
Socket#2:0x17 1815 D:192.168.0.102(80)
Socket#3:0x0 0 D:0.0.0.0(0)
Connecting To House Controller.
*************************************************
Stopping Client after initial connection failure.
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x17 1814 D:192.168.0.102(80)
Socket#2:0x15 6746 D:192.168.0.102(80)
Socket#3:0x0 0 D:0.0.0.0(0)
Uptime: 302 Mins.
Connecting To House Controller.
*************************************************
Stopping Client after initial connection failure.
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x17 1814 D:192.168.0.102(80)
Socket#2:0x17 6746 D:192.168.0.102(80)
Socket#3:0x0 6747 D:192.168.0.102(80)
Uptime: 303 Mins.
Connecting To House Controller.
*************************************************
Stopping Client after initial connection failure.
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x17 1814 D:192.168.0.102(80)
Socket#2:0x17 6746 D:192.168.0.102(80)
Socket#3:0x0 6748 D:192.168.0.102(80)