Labels

Wednesday, 4 November 2026

ESP32 Telnet

ESPTelnet

After successfully investigating SSH terminal access to ESP32 and recognising that SSH security is complex and not required for my purposes I decided to try telnet.

Google gives some choices for a telnet server, I chose to install ESPTelnet


As this is back in Arduino land testing becomes easier.  I simply installed ESP Telnet library by Lennart Hennings and found in the examples "TelnetServerExample.  After uploading I see console messages to show that Telnet is up and running.  I can then Telnet in from my PC.  As usual there are not much of a shell provided, text typed in is echoed. Input from the client is processed by a function "onTelnetInput" which has a couple of commands "ping" and "bye".
 


I want to run programs on my ESP32 as well as controlling / monitoring it through remote access.  To test this I added a simple blink program to the example. When ESP32 is started the system LED is turned on/off each second.  The sketch works fine.  The only snag is that Telnet response drops.  When you type something you have to wait about 10s for a response.  The blink loop repeats every two seconds meaning the telnet loop can only work between loops.  Clearly the loop() function cycle time needs to be kept short to allow telnet processing.  For example a non-blocking version of blink would  need to be written.

Google Telnet

I googled "esp32 remote terminal" to identify potentially useful resources.  Google AI came up with an informative answer.  When I clarified my request it gave me a complete program!

I couldn't resist taking Google up on its offer. I copied code into a sketch entered my user/password and compiled it.  It didn't require installation of libaries and did exactly what I wanted!

Async Telnet

It is very pleasing to setup a telnet server with so little effort.  To be a practical tool, telnet needs to interfere as little as possible with useful work, the job for which we are using ESP32.  To do this we need non-blocking code, in practice this means we shouldn't need to include telnet commands within arduino loop() function.  Telnet functions should be invoked when needed using callback functions.

"Async Telnet for ESP32" by Frank Boesing seems to be perfect.
  

I copied source code snippetes into a sketch, added wifi initialisation code to setup() built the sketch and it worked.  I see a console message "Telnet server active" and I can telnet into ESP32 from a WSL command prompt.
By default the sketch is setup as a "log server" where communication is one way, so that ESP32 can transmit information to the telnet client.  Once I enabled the "handle incoming data" variable anything typed on Telnet client was returned to ESP32 and handled by a callback function.  Typically, this function will allow commands to be transmitted to ESP32 for control purposes.

Outro


AsyncTelnet gives me a much easier, appropriate solution to my desire for remote access.  It can be implemented without obstructing other software running on ESP32 and should be part of my overall ESP32 remote access objective.

I did have one problem getting AsyncTelnet code to work which led to my first productive use of AI which I will write about next.


No comments:

Post a Comment