Open hamidtb opened 1 year ago
the delay
is your loop
is most likely the problem.
the headbeat from the server is missed, since you call the WS loop function only every 6sec.
try to use this pattern for running code in intervals instead of the delay.
static unsigned long last_run;
void loop() {
unsigned long now = millis();
objWebSocketClient.loop();
if(now - last_run >= 6000) {
objWebSocketClient.sendTXT("Hello FROM ESP32!");
last_run = millis();
}
}
Note: code not tested, but sure works a a hint ;)
thanks a lot; Its work perfect
Is that code cause Pressure on the device's CPU?
I also see two functions: 1-websocketclient.enableHeartbeat(); 2-websocketclient.sendping();
How to use them to keep the connection alive?
sendping
can be used to send one ping manually, this is mostly use full for checking if the TCP connection is still working.
enableHeartbeat
automates sending pings and waiting for the response (and on timeout reconnecting).
all is handled inside the loop
function, and only works it loop
is called regularly.
after the connection is established the loop
function does only does check if new TCP data is there form there server and the timeout handling.
if there is no new data the function exits quickly so no big resource usage there.
the arduino TCP interface is poll only so no way around it ;)
hi I recently wrote code in my ESP32 using your library, but the server log showed many connects and disconnects, and I received no data from the server. This is my code.