Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ESP8266 Telnet link watchdog

Status
Not open for further replies.

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
16,214
Helped
5,138
Reputation
10,305
Reaction score
5,111
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
137,224
Here's an interesting problem to which I'm open to ideas:

Scenario - an ESP8266 module is plugged into a control system via a serial link. The link is a very basic TX/RX connection via a MAX3232, no handshaking is used. The module runs as a Telnet interface and is linked to a WiFi router nearby. The WiFi link works fine and is reliable. The router 'port forwards' the module IP address (fixed) to a public external address and port number (also fixed), this allows external access through the Internet to the router and then the ESP8266 module. All works perfectly.

Problem - when accessed from a fixed location, wherever it is, the connection is reliable even after many days. However, when accessed from a mobile device, for example a 3G/4G phone, it sometimes permanently locks up with the mobile end receiving a "closed by foreign host" message. My investigation shows that what happens is when the mobile device either loses signal or moves to a different cell, it gets a new IP address from the Telco but the ESP8266 still has the original Telnet connection running and only one connection at a time is allowed. So the connection does reach the ESP8266 but it sees a second user with the first one still logged in and refuses the session.

I could allow more than one user at a time to connect but that would only delay the problem. The module still sees the local router all the time so I can't use a loss of WiFi connection to force a reset. Unfortunately, the ESP8266 Telnet code resets the internal watchdog inside it's library code so I can't rely on it to force a hardware reset after a period of inactivity. Typical incoming data to the ESP8266 is only a few command bytes and the outgoing data can be anything from one byte to about 32K bytes.

Anyone have any ideas?

The best I can come up with is an external timer hooked to the reset pin and reset by data leaving the ESP8266 TX pin. The idea being that no incoming data from the internet means nothing should come out of the TX pin so the connection might be lost. The drawback to this is it would put the module into a periodic reset loop when not being used with a few seconds of dead time each pass of the loop while it re-initializes and logs back into the router.

Brian.
 

Can't TCP keepalive be used to terminate the dead connection?
 

Thanks FvM.

I'll look into that as an option but I think it needs a regular 'ping' to keep it awake and I'm not sure that can be implemented in the existing system. The problem is the WiFi link to the ESP8266 is always on and it is always connected, it's the IP address of the mobile device that changes and makes Telnet think the user is someone else.

I can simulate the problem here by connecting to an ESP8266 through Telnet-->3G-->mobile network / ADSL-->router-->WiFi-->ESP-->terminal which gives a transparent serial link but if I turn the 3G signal off and back on again, the connection is refused. The mobile network has allocated a different IP address and it sees me as a second user.

As the command set is quite small, I could try converting from Telnet to HTTP so it disconnects and reconnects at each request but it would take a lot of programming. I think the easiest solution might be a small supervisory MCU (PIC10F or similar) that looks for long gaps in incoming data and drives the ESP reset pin. Not ideal but it would also allow me to suppress the ESP boot data so it doesn't reach the system.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top