I am using a Lolin Nodemcu and when running the code, sometimes the websocket client connects and then disconnects inmediately. When this happens I restart the nodemcu and then it works, but it is a recurrent problem. I am using the WebsocketsClient.
For now, I am using the following code, but I don't know if there is a better way to ensure it reconnects.
// Connect to server (in setup)
socketConnected = client.connect(websockets_connection_string);
//Check if it failed to connect (in loop)
if (!socketConnected) {
socketConnected = client.connect(websockets_connection_string);
unsigned long ms3 = micros();
while ((micros() - ms3) < 30) {
}
}
I am using a Lolin Nodemcu and when running the code, sometimes the websocket client connects and then disconnects inmediately. When this happens I restart the nodemcu and then it works, but it is a recurrent problem. I am using the WebsocketsClient.
For now, I am using the following code, but I don't know if there is a better way to ensure it reconnects.