arduinoWebSockets icon indicating copy to clipboard operation
arduinoWebSockets copied to clipboard

Error messages with ESP32 usage

Open friedemannm opened this issue 6 years ago • 14 comments

Hi!

I'm using this library since a while on the ESP8266 where it worked like a charm! Now I switched to the ESP32 with the following warnings:

[E][WiFiClient.cpp:261] setSocketOption(): 1006 : 9 [E][WiFiClient.cpp:282] setOption(): fail on fd -1, errno: 9, "Bad file number"

Besides this, we have connection problems. There are random disconnects from time to time. Does anybody has an Idea where to start debugging this?

Please let me know If further informations are needed.

Thanks in advance, Friedemann

friedemannm avatar Sep 13 '19 15:09 friedemannm

Hi,

what ESP8266 core version do you use? the lines in you error message do not line up with the latest version: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClient.cpp#L261

may enable the build in debug messages of the lib via the IDE menu to get more context to when the error happens.

Links2004 avatar Sep 13 '19 16:09 Links2004

Thanks a lot for the fast reply! There was a typo in my post - I switched from ESP8266 to ESP32. I think it makes more sense now ;) Sorry for that... The warning comes up while connecting via SSL to a websocket server. I'm using the SHA Hash to check the server certificate.

friedemannm avatar Sep 13 '19 17:09 friedemannm

Does that only happen with a SSL connection?

Links2004 avatar Sep 14 '19 07:09 Links2004

Hi! Sorry for late reply. Yes, the warning only appears when using SSL. The connection loss problem is incredibly unpredictable. For now it could also be a hardware issue related to the current supply... How to enable the debug messages you mentioned in vs code with platformio?

friedemannm avatar Sep 22 '19 17:09 friedemannm

for platformio you need to set the defines in your platformio.ini

something like this:

build_flags = -D DEBUG_ESP_PORT=Serial

but since its a SSL only problem its more likely the SSL Implementation then the WebSockets code, since SSL and non SSL share the same code for the data handling. but with the messages we may know more.

if I remember correct then the ESP32 has a code_debug level that gets you more Internal logging too, not sure if it helps in this case.

so may use

build_flags = -D DEBUG_ESP_PORT=Serial -DESP32 -DCORE_DEBUG_LEVEL=5

Links2004 avatar Sep 23 '19 16:09 Links2004

Hey!

Sorry for the long delay - Here are the logs of such a disconnect scenario. In meanwhile I found out that it isn't only a ESP32 problem. The logs posted below come from an 8266. For me it's not too clear what exactly happened. Obviously a timeout somewhere... But what can I do to avoid this?

Thank you very much and alle the best, Friedemann

Message received: ping
[WS][0][sendFrame] ------- send message frame -------
[WS][0][sendFrame] fin: 1 opCode: 2 mask: 1 length: 18 headerToPayload: 0
[WS][0][sendFrame] pack to one TCP package...
[write] n: zu t: 24
[WS][0][sendFrame] sending Frame Done (16144us).
[WS][0][sendFrame] ------- send message frame -------
[WS][0][sendFrame] fin: 1 opCode: 2 mask: 1 length: 73 headerToPayload: 0
[WS][0][sendFrame] pack to one TCP package...
[write] n: zu t: 79
[WS][0][sendFrame] sending Frame Done (15244us).
[WS][0][handleWebsocketWaitFor] size: 2 cWsRXsize: 0
[readCb] n: zu t: 2
[WS][0][handleWebsocketWaitFor][readCb] size: 2 ok: 1
[WS][0][handleWebsocket] ------- read massage frame -------
[WS][0][handleWebsocket] fin: 1 rsv1: 0 rsv2: 0 rsv3 0  opCode: 2
[WS][0][handleWebsocket] mask: 0 payloadLen: 25
[readCb] n: zu t: 25
Message received: ACK
Ack.
bcn_timout,ap_probe_send_start
ap_probe_send over, rest wifi status to disassoc
state: 5 -> 0 (1)
rm 0
pm close 7
[WS-Client] connection lost.
[WS-Client] client disconnected.

friedemannm avatar Oct 10 '19 07:10 friedemannm

Again a disconnect - this time with another debug message...

WS][0][sendFrame] ------- send message frame -------
[WS][0][sendFrame] fin: 1 opCode: 2 mask: 1 length: 73 headerToPayload: 0
[WS][0][sendFrame] pack to one TCP package...
[write] n: zu t: 79
[WS][0][sendFrame] sending Frame Done (14810us).
state: 5 -> 2 (7c0)
rm 0
pm close 7
[WS-Client] connection lost.
[WS-Client] client disconnected.

friedemannm avatar Oct 10 '19 08:10 friedemannm

the

state: 5 -> 2

and

state: 5 -> 0 (1)

are WiFi state changes so you WiFi connection is instabile, its not a TCP or Websocket problem we are looking at here.

if possible you can try to use a other AP / Router.

may the WiFi.onStationModeDisconnected helps you to debug this since it can provide you with a reason for a disconnect.

https://github.com/esp8266/Arduino/blob/74819a763bfb6e9890a57411dcea4aba221a778d/doc/esp8266wifi/generic-examples.rst

https://github.com/esp8266/Arduino/blob/273f4000f0dcb936e457cba3e71d824a7dfb9007/libraries/ESP8266WiFi/src/ESP8266WiFiType.h#L68-L99

https://github.com/esp8266/Arduino/blob/273f4000f0dcb936e457cba3e71d824a7dfb9007/libraries/ESP8266WiFi/src/ESP8266WiFiType.h#L114-L119

Links2004 avatar Oct 10 '19 18:10 Links2004

hi, you solved the problem [E][WiFiClient.cpp:261] setSocketOption(): 1006 : 9?

a-silent88 avatar Oct 13 '19 12:10 a-silent88

Hey! I'm still not sure if its really a problem or just a warning. But the answer is no. I'm still getting this warning. Do you also have problems with random reconnects?

friedemannm avatar Oct 13 '19 12:10 friedemannm

No, I don't have problems with reconnects, my esp32 just freezes :-))) Thank you for answer.

a-silent88 avatar Oct 13 '19 13:10 a-silent88

Try using class instance WiFiClientSecure, my error is gone. (http://www.iotsharing.com/2017/08/how-to-use-https-in-arduino-esp32.html) Sorry for my english

a-silent88 avatar Oct 13 '19 16:10 a-silent88

My esp32 restarts if I tried to go beyond the heap limit char array[10]; char i = array[10]; or something like that uint8_t j = 1000;

a-silent88 avatar Oct 13 '19 17:10 a-silent88

I know its kinda late, but I had the same error. The issue was that I was trying to configure the connection before it started, for example if you call .setTimeout() before .begin initializes the connection. The error will always appear.

fcojacuna avatar Aug 23 '22 18:08 fcojacuna