-
Notifications
You must be signed in to change notification settings - Fork 582
Description
Hi all, I have a situation where I try to connect to a server, and call webSocket.loop() which the first time round returns, however on the second loop call, it doesn't make it through the function.
I have not dived too far into the code because I am sure support here will guide this debugging process.
The code is using version 2.7.1 and is as follows:
WebSocketsClient webSocket;
webSocket.begin("136.243.4.163", 28082);
webSocket.onEvent(webSocketEvent);
webSocket.setReconnectInterval(1000);
In my main loop I have:
webSocket.loop();
Sometimes the above code works nicely and I get a connected event arriving into my webSocketEvent handler:
void webSocketEvent(WStype_t type, uint8_t *payload, size_t length)
{
switch (type)
{
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED:
Serial.printf("[WSc] Connected to url: %s\n", payload);
webSocket.sendTXT("Connected");
break;
case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload);
break;
case WStype_BIN:
Serial.printf("[WSc] Received response binary length: %u\n", length);
decode_response(payload, length);
break;
case WStype_ERROR:
case WStype_FRAGMENT_TEXT_START:
case WStype_FRAGMENT_BIN_START:
case WStype_FRAGMENT:
case WStype_FRAGMENT_FIN:
break;
}
}
However in the case I am currently experiencing, the begin call is made, the code flows into the main loop of the ESP32, I make one call to the webSocket.loop() - which runs top to bottom, then a second called to webSocket.loop() occurs, and I can see the call arriving into the top of webSocket.loop() but it never reaches the bottom of the code (I use Serial.printf to debug).
Can anyone help me here? Why would webSocket.loop() be hanging - and is this expected behaviour given certain conditions? Perhaps there are some other best practices I am not using on my connection attempt.
Many thanks for help and support!