TelNetStream - ESP8266 - disconnect?

I have a ESP8266 on a wifi connected to a Raspberry Pi. Both are always on, and to capture occasional events happening on the ESP, I use the TelNetStream library, as provided by Arduino/juraj. I then telnet to my ESP ip address from a tmux session on the Raspberry Pi. I see the messages from the ESP8266 coming on my tmux session and I hoped to go happily do something else and check a few hours later. However, then my Raspberry tmux session shows me: "connection closed by foreign host" ... must be some time-out somewhere ... any suggestions in how I can prevent this time-out from happening?

Try sending something regularly to prevent either end deciding to time out the connection because it's not being used. Generally speaking this is know as a "keep alive" message. Have your receiver code ignore keep alive messages. You could literally send "keep alive".

The ESP8266 has a Wi-Fi power-saving mode that could disconnect idle connections. Try disabling it:

WiFi.setSleep(false);

Place this in your setup() function.

I followed the 'keep alive' idea and send a '.' every 10 seconds - that seems to work. My ESP8266 never goes in low-power or sleep mode..

1 Like

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