gilmaimon / ArduinoWebsockets

A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
GNU General Public License v3.0
482 stars 97 forks source link

Disconnect with code 1002 #88

Closed jackorp closed 4 years ago

jackorp commented 4 years ago

Describe the bug I have a web app sending data every circa 0.06s (60ms) over WebSocket which then parses colors sent as a message and assigns it to the LED strip. Although, after a while the esp-01 disconnects with code 1002.

To Reproduce

Expected behavior End with a more meaningful message/code because I am not sure if the internal workings of esp8266 or this library are responsible.

Code Link: https://gitlab.com/jackorp/arduino_color_server/-/blob/master/multi_color_LED/multi_color_LED.ino

Additional context Possibly related issue: #75

gilmaimon commented 4 years ago

Hi,

I see you are using your own server impl, just making sure: it's a websocket server right?

Also, did you implement the websocket logic yourself or is it a public library? If you made it yourself, consider trying out the server with another client. If not, we can debug the library together to understand exactly what's the mistake.

Gil.

jackorp commented 4 years ago

Hi, its a bit combined classic HTTP and websocket and but all the underlying logic is implemented by a library, namely Nio::WebSocket. I defined callbacks and a loop that sends data over to the esp-01 client. I will try it out with another client and get back to you.

jackorp commented 4 years ago

I tested it with nodejs WebSocket client library and no problems.

I tried it more extensively with esp-01 and around 30 minute (+- 5 minutes) mark, the chip even restarts itself. I am leaning towards some software fault because a power fault would be more random IMHO. I'll connect up Tx and Rx pins later to try and see some more debug info.

Any suggestions on what I should be looking for? I am more a hobbyist in the embedded / low-level C(++) lang area.

gilmaimon commented 4 years ago

Hard to say. If the disconnect happened when connecting to the server I would say there is probably some header mismatch. But only after a while is weird. I can recommend adding Serial.printlns to the library where a protocol error (1002) is being returned. Other than that, because I'm not actively working on the library these days, I can't help and debug it myself..

jackorp commented 4 years ago

I did some debugging. The return code 1002 might be the result of an abrupt disconnect caused by hardware wdt reset probably caused by an insufficient power input. JFTR some of my loops might have made it worse by not giving enough cycles to the ESP chip to do its internal stuff so I added the yield() method to prevent this problem.

tl;dr 90% confidence the problem is on my side.