-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disconnection detection issue #864
Comments
the ESP tcp socket only notices that the socket is dead when something is send. arduinoWebSockets/src/WebSocketsClient.h Line 102 in 6a26f74
after a send failes the client disconnects and the event for the websocket has a ping build in and it can be enabled with backround: |
Tell me please, how long can a WebSocket Client connection be? I would like to send some sensor data over it in JSON, and the scenario is that sensor should be online 24/7 |
there is no limit on the arduinoWebSockets side, it all depends on how your server is setup and how stable the WiFi / Network connection is. |
I would be very happy if you could share an example how to use heartbeat. |
I could only recommend using https://arduinojson.org/, on ESP32 there is no real RAM concern as they have a lot. |
yes using JSON is works with ESP8266 and ESP32 fine. e.g. DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, payload, length);
if(error) {
USE_SERIAL.print(F("deserializeJson() failed: "));
USE_SERIAL.println(error.c_str());
return;
}
heartbeat only needs to be enabled. arduinoWebSockets/src/WebSocketsClient.h Line 102 in 93707d4
|
Hello again. Here i have a few questions:
|
yes client.enableHeartbeat is called in the setup process, and yes all times are in milliseconds. arduinoWebSockets/src/WebSocketsClient.cpp Lines 962 to 970 in 93707d4
|
@Links2004 for "client" this solution seems to work fine. How about the same scenario but for "server" (I'm testing an ESP32 with WebSocket server behind NAT (Internet->Router(NAT)->Switch->ESP32 w LAN) and if i pull out the cable between Router and Switch, how can "server" handle that? |
any reason to not use arduinoWebSockets/src/WebSocketsServer.h Line 90 in 93707d4
each side can send a ping, the ws protocol allows it. |
Hi Links2004, |
Hi,
I'm working on a disconnect scenario to improve the documentation and my workflow.
My computer is running a WebSocket server.
The ESP32 is the client. (
WebSocketsClient webSocket;
)1 - Disconnected from server shutdown
✅ Seems to work properly and properly detected by the library.
2 - Switching the network from the server
To simulate disconnection, I also switched off the WiFi on my computer, so the server is no longer reachable.
This is an edge case I guess but why can't this happen?
❌ The ESP32 with socket doesn't detect the disconnection. Within
onEvent
->WStype_DISCONNECTED
Current workaround
Currently, I'm pinging frequently the server and if the last message is > 10 seconds, I consider it off.
Do you think the library can handle this scenario of failure without having to rely on custom code for pings?
The text was updated successfully, but these errors were encountered: