+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Super Moderator
    Points: 73,711, Level: 66
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,069
    Helped
    3998 / 3998
    Points
    73,711
    Level
    66

    ESP8266 Telnet link watchdog

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

    •   AltAdvertisment

        
       

  2. #2
    Super Moderator
    Points: 248,101, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    43,148
    Helped
    13128 / 13128
    Points
    248,101
    Level
    100

    Re: ESP8266 Telnet link watchdog

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



    •   AltAdvertisment

        
       

  3. #3
    Super Moderator
    Points: 73,711, Level: 66
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    12,069
    Helped
    3998 / 3998
    Points
    73,711
    Level
    66

    Re: ESP8266 Telnet link watchdog

    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.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



--[[ ]]--