The use of the ESP8266 in the world of IoT

User avatar
By Ranjith R
#87440 Dear all,

Use case:
I'm having a TCP server application running in Ubuntu. This server manages all the connected clients and their states(Online/Offline).

When a client connects, server makes its state to "Online". When a disconnection is detected, the server updates its state to "Offline".

Issue:
I use the esp8266 in station mode and make TCP connection to the server using the WifiClient class. The problem here is, on power failures(unplugging of usb) of esp8266, the server is not receiving the disconnection, unless WifiClient.stop() is explicitly called. Thus the server shows up a false online status for esp8266 client.

For implementing a graceful shutdown, I've been thinking of ways to create a cheap and compact backup power source at the esp8266 side, like a capacitor, which provide some backup power to execute some cleanup routine on power failures. Will this be enough to get enough cycles to execute WifiClient.stop()? Has anybody came across such a use case before?

All suggestions & help would be appreciated.

Thank you!
User avatar
By davydnorris
#87450 This is the way TCP/IP works unfortunately - the protocol itself is responsible for implementing a way to detect broken connections, there's nothing at the TCP level that does it.

What I have done is to use MQTT protocol, which has a heartbeat that you can set - if the client (or server) misses the heartbeat for too long then the connection is declared dead and can be reported on as part of the protocol. In fact you can personalise the reporting by using MQTT's Last Will and Testament (LWT), which lets a client specify a topic and a message to publish on behalf of the client if the connection is deemed dead.
User avatar
By davydnorris
#87461
Pablo2048 wrote:Also you can implement TCP Keepalive mechanism (especially designed for this usecase) on Ubuntu side (https://tldp.org/HOWTO/TCP-Keepalive-HO ... rview.html).


Yes that should work well, and your Ubuntu server can be enabled to do that.