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

Disconnecting almost inmediately #150

Open Ale-Coeto opened 1 year ago

Ale-Coeto commented 1 year ago

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) {

      }

  }