How to detect "slow" web socket connection, if client fall asleep?

I have ESP8266 device, and using web page with web-socket client on JavaScript to control such device. I would like to have indication on the web page showing connection status, like connected/disconnected. ESP8266 device controls ws2812 led strip with dynamic effects, and must to operate without big delays in the loop.

Currently, I am not using heartbeat, I have json packet sends from ESP8266 side to client side every second, containing real time clock (my esp8266 device has NTP support), and on the web page I have shown that clock time info, or show "Not Connected" if such packet was not received within 1.5 second. It works perfectly most of the time, but I have observed rare situation, may be once in a week, when client device with browser (cell phone, for example) falls asleep, but did not brake the connection, connection is still alive. In this situation ESP8266 device (web socket server-side) still sends every second packets, but transmission is very stuttering, causing big time delays, which seriously affects real time operation of ESP8266 device.

What is the proper way to handle it?
Should I use heartbeat mechanics instead of sending json packet every-second, will it give me any advantage with such problem? I can get rid of the idea to indicate real time clock on the web page, but I would like to have better connection/disconnection control, not causing big delays...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.