Telnet Server

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Telnet Server

Post by chrisgp » Wed Oct 05, 2016 5:00 am

I implemented a trivial telnet server for MicroPython/ESP8266 that will run in the background and give telnet clients access to the REPL. The code is here: https://github.com/cpopp/MicroTelnetServer

I've only tested with the mac telnet client, but to use it you just throw utelnetserver.py on your ESP8266 and add the following lines to boot.py

Code: Select all

import utelnetserver
utelnetserver.start()
and from there you should be able to telnet to your ESP8266.

User avatar
deshipu
Posts: 1374
Joined: Thu May 28, 2015 5:54 pm

Re: Telnet Server

Post by deshipu » Wed Oct 05, 2016 7:50 am

Awesome! That will surely be useful!

User avatar
Roberthh
Posts: 2135
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Telnet Server

Post by Roberthh » Sun Oct 09, 2016 7:41 am

This program works and looks very elegant, but seems to drop characters sometimes during reading. This can be observed e.g. by

Code: Select all

print("*******************************")
put into the paste buffer and then submitted with keyboard autorepeat. With shorter strings it works.

User avatar
pythoncoder
Posts: 4471
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Telnet Server

Post by pythoncoder » Sun Oct 09, 2016 4:13 pm

This does look very useful! Another issue, though. Paste mode doesn't work: when you press ctrl-D to exit paste mode it issues a syntax error and the code pasted is not compiled.

I've not seen it drop characters in mid-stream, but there does seem to be evidence of a limited buffer size. I filled the paste buffer with this:

Code: Select all

print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
print("*******************************")
Pasting that at the Telnet prompt produced this, quite repeatably

Code: Select all

>>> print("*******************************")
*******************************
>>> print("*******************************")
*******************************
>>> print("*******************************")
*******************************
>>> print("*******************************")
*******************************
>>> print("*******************************")
*******************************
>>> print("*******************************")
*******************************
>>> pri
The session still runs - nothing is actually broken, but it seems that a character buffer may have filled. It would be good if these were fixed because it's very handy to be able to paste multi-line functions at the REPL.
Peter Hinch

chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Re: Telnet Server

Post by chrisgp » Sun Oct 09, 2016 6:18 pm

I made a few improvements while investigating this but as far as I can tell this is a deficiency in the underlying dupterm handler in the firmware.

For example, trying pasting the following into the WebREPL (or my telnet server), or any payload over 256 bytes:

Code: Select all

'****************************************************************************************************************************************************************************************************************************************************************'
you'll notice the response gets truncated in either case. It looks like the dupterm handler reads input characters into a ring buffer (https://github.com/micropython/micropyt ... phal.c#L39) but that ring buffer has a length of 256 bytes, so if data is coming in quickly enough to fill the ring buffer some will be overwritten.

chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Re: Telnet Server

Post by chrisgp » Sun Oct 09, 2016 7:09 pm

Thanks for finding that paste mode was busted @pythoncoder. I was able to fix it so paste mode should work now. The telnet client was writing null bytes into the stream that I wasn't stripping before handing them off to dupterm. The latest code has the fix.

As for the multiple print statements I tried that against the WebREPL and it fails there as well, I opened https://github.com/micropython/micropython/issues/2497 to track it.

User avatar
pythoncoder
Posts: 4471
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Telnet Server

Post by pythoncoder » Mon Oct 10, 2016 6:20 am

That's a great improvement. @Damien seems to be onto #2497 so hopefully that will be fixed before long. A workround is to paste the code in a few lines at a time.

One oddity is that the REPL can be quite slow. I'm not a fast typist but I sometimes get well ahead of the echo. However this seems variable and I'm suspecting it's a local WiFi issue. Has anyone else experienced this?
Peter Hinch

User avatar
Roberthh
Posts: 2135
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Telnet Server

Post by Roberthh » Mon Oct 10, 2016 6:56 am

It were not only long pastes which cause a problem. It seems that also a very fast burst of a few characters may be an issue. I see that in a certain situation, e.g. on autorepeat of the cursor keys, but I have to track it down further.

User avatar
pythoncoder
Posts: 4471
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Telnet Server

Post by pythoncoder » Mon Oct 10, 2016 7:14 am

I've not seen that one yet. I've been using it with the FTP server and they work together well. The Telnet server does seem to be a bit greedy of RAM (9424 bytes used) given that I'm running it as frozen bytecode. This would limit the user applications you could run.

By contrast the FTP server uses very little (usage goes from 9424 to 10016). It doubtless uses more when you access it, but in that instance you won't be expecting a user application to be running concurrently. Such is the curse of Telnet...

My sluggish response seems to have vanished. I'm becoming convinced that something periodically affects my WiFi :(
Peter Hinch

chrisgp
Posts: 41
Joined: Fri Apr 01, 2016 5:29 pm

Re: Telnet Server

Post by chrisgp » Mon Oct 10, 2016 2:24 pm

My guess is that regardless of whether it is a single long payload or a smaller payload repeatedly pasted faster than it can be processed the buffer would get filled and cause dropped characters (hopefully). I did also see problems with the WebREPL when repeatedly pasting -- I'll try out both scenarios again once 2497 is fixed.

That's pretty interesting that the telnet library uses more memory than the ftp server since it's code size is much smaller. When I get a chance I'll take a look at it...maybe some of the libraries I'm importing are bloating it a bit.

Post Reply