Exception (28) when TCP client disconnects
Posted: Sun Dec 23, 2018 10:10 pm
If I take the sample WiFiServer code at:
https://techtutorialsx.com/2018/06/02/e ... et-server/
it works fine as it stands. I can connect to it and disconnect multiple times without a problem.
I wanted to clean up the code in void Loop() so I placed the code into its own function:
I pass in the WiFiServer object to the handler like this in loop()
The sketch runs but after the first time any client disconnects from it - I get an exception (28):
Am I doing something stupid with the object getting passed into the new function? If I don't pass the object in and refer to the global object instead, it works fine. The reason I want to pass the WifiServer object to the handler is because I want to place the handler code into its own file (which I then include), so that I can keep that code separate for use in multiple sketches, and if I dont pass the object in, the compiler complains that the object is not declared in scope.
Here is the entire sketch:
and here is the exception:
https://techtutorialsx.com/2018/06/02/e ... et-server/
it works fine as it stands. I can connect to it and disconnect multiple times without a problem.
I wanted to clean up the code in void Loop() so I placed the code into its own function:
Code: Select all
void handleServer(WiFiServer remotesign){
WiFiClient rs = remotesign.available();
if (rs) {
while (rs.connected()) {
while (rs.available()>0) {
char c = rs.read();
Serial.write(c);
}
delay(10);
}
rs.stop();
Serial.println("\nAfter no stop");
}
}
I pass in the WiFiServer object to the handler like this in loop()
Code: Select all
handleServer(wifiServer);
The sketch runs but after the first time any client disconnects from it - I get an exception (28):
Am I doing something stupid with the object getting passed into the new function? If I don't pass the object in and refer to the global object instead, it works fine. The reason I want to pass the WifiServer object to the handler is because I want to place the handler code into its own file (which I then include), so that I can keep that code separate for use in multiple sketches, and if I dont pass the object in, the compiler complains that the object is not declared in scope.
Here is the entire sketch:
Code: Select all
#include "ESP8266WiFi.h"
const char* ssid = "xxx";
const char* password = "xxx";
WiFiServer wifiServer(50601);
void handleServer(WiFiServer remotesign){
WiFiClient rs = remotesign.available();
if (rs) {
while (rs.connected()) {
while (rs.available()>0) {
char c = rs.read();
Serial.write(c);
}
delay(10);
}
rs.stop();
Serial.println("\nAfter stop");
}
}
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
wifiServer.begin();
}
void loop() {
handleServer(wifiServer);
}
and here is the exception:
Connecting..
22:08:16.246 -> Connected to WiFi. IP:192.168.86.137
{NAME}Betreibswerk
{VER}3.6
After stop
22:08:20.085 ->
22:08:20.085 -> Exception (28):
22:08:20.085 -> epc1=0x40204327 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000157 depc=0x00000000
22:08:20.085 ->
22:08:20.085 -> ctx: cont
22:08:20.085 -> sp: 3ffffd20 end: 3fffffd0 offset: 01a0
22:08:20.085 ->
22:08:20.085 -> >>>stack>>>
22:08:20.085 -> 3ffffec0: 40203fc1 00000030 0000001b ffffffff
22:08:20.085 -> 3ffffed0: 40100739 00000000 00000001 00000001
22:08:20.085 -> 3ffffee0: 40104ab2 001be21b 00000139 3ffeea98
22:08:20.085 -> 3ffffef0: 3ffeeb10 000000d8 000000d8 4010020c
22:08:20.085 -> 3fffff00: 3fffdad0 00000000 3ffef6dc 401006dc
22:08:20.120 -> 3fffff10: 3ffe8ae8 3ffeeaec 3ffe850c 40203e60
22:08:20.120 -> 3fffff20: 402044b0 00000000 00001388 40202fe7
22:08:20.120 -> 3fffff30: 00000000 3ffef6dc 3ffee9d8 40203160
22:08:20.120 -> 3fffff40: 3fffdad0 00000000 3ffeea90 402025a3
22:08:20.120 -> 3fffff50: 402044b0 00000000 00001388 4020b05b
22:08:20.155 -> 3fffff60: 00000000 3ffef6dc 3ffef72c 4020371a
22:08:20.155 -> 3fffff70: 00000000 3ffee98c 3ffeea90 4020263a
22:08:20.155 -> 3fffff80: 40204508 00000000 3ffec5a9 40204558
22:08:20.155 -> 3fffff90: 00000000 3ffef93c 00000000 00000000
22:08:20.155 -> 3fffffa0: 00000000 00000000 00000001 40203f4d
22:08:20.190 -> 3fffffb0: 3fffdad0 00000000 3ffeea90 40203fb8
22:08:20.190 -> 3fffffc0: feefeffe feefeffe 3ffe850c 40100739
22:08:20.190 -> <<<stack<<<
22:08:20.190 ->
22:08:20.225 -> ets Jan 8 2013,rst cause:2, boot mode:(1,6)
22:08:20.225 ->
22:08:27.424 -> ets Jan 8 2013,rst cause:4, boot mode:(1,6)
22:08:27.459 ->
22:08:27.459 -> wdt reset