Telnet Server

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Telnet Server

Post by Roberthh » Mon Oct 10, 2016 6:50 pm

As far as I could tell, importing & starting the telnet server reduced the free memory by 1616 bytes, and it's not frozen bytecode. As frozen bytecode, it's 640 bytes.

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

Re: Telnet Server

Post by pythoncoder » Tue Oct 11, 2016 9:22 am

Oops, sorry. Brain fade yesterday. Some figures based on frozen bytecode on the reference board.

Accessing via USB:
After import, usage 480 bytes
After starting server 608 bytes.

I then edited main.py to run it at boot, power cycled the board and accessed it over WiFi via Telnet. Usage (relative to the free RAM reported in the first test) was 1408 bytes.
Peter Hinch
Index to my micropython libraries.

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: Telnet Server

Post by warren » Wed Dec 14, 2016 8:21 am

This is very useful. but I have a strange problem when typing.

I am connecting to the ESP8266 module over my LAN. I am using Putty for telnet. It connects immediately and in the Putty window I see the same flow of stuff on REPL as I am seeing through the serial connection.

When I type I cannot see what I am typing!

But what I type is definitely received and acted upon by REPL...its just that I cant see it when i am typing. And this applies to BOTGH the Putty console and on the serial view - when I am typing, nothing shows.

Also, CTRL-C does not work

Any hints?

Thanks

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

Re: Telnet Server

Post by Roberthh » Wed Dec 14, 2016 7:57 pm

That seems to be a putty configuration problem. It seems to be in line edit mode. In the terminal setting of putty's configuration, set local line editing to force off. Then it works.

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: Telnet Server

Post by warren » Thu Dec 15, 2016 6:02 am

Roberthh wrote:That seems to be a putty configuration problem. It seems to be in line edit mode. In the terminal setting of putty's configuration, set local line editing to force off. Then it works.
Doh!

Thanks so much - works perfectly.

jpj
Posts: 60
Joined: Sat Dec 10, 2016 3:07 pm

Re: Telnet Server

Post by jpj » Thu Dec 15, 2016 1:14 pm

Very useful! Thank you for writing and sharing it.

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: Telnet Server

Post by ttmetro » Tue Dec 05, 2017 3:39 am

Will this telnet server (or any other telnet) work with the standard (official) ESP32 microphython port?

[ I've been using the Pycom and the Loboris ports for this feature; both are (more or less) subtly different from standard microphython. ]

Bernhard
Bernhard Boser

Jongy
Posts: 9
Joined: Fri Jun 08, 2018 11:50 am

Re: Telnet Server

Post by Jongy » Thu Feb 21, 2019 8:00 pm

ttmetro wrote:
Tue Dec 05, 2017 3:39 am
Will this telnet server (or any other telnet) work with the standard (official) ESP32 microphython port?

[ I've been using the Pycom and the Loboris ports for this feature; both are (more or less) subtly different from standard microphython. ]

Bernhard
I've tried this now on an ESP32 and it doesn't work, getting this error:

Code: Select all

Traceback (most recent call last):
  File "utelnetserver.py", line 81, in accept_telnet_connect
OSError: stream operation not supported
which is quite expected by looking at the code, I admit.

Anyway I've come to a conclusion that I want telnet on my ESP32 because it would work much more smooth compared with the webrepl, so I'll keep you updated once I get this working :)

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

Re: Telnet Server

Post by Roberthh » Thu Feb 21, 2019 8:30 pm

The change is simple. According to the hint here viewtopic.php?f=8&t=5868&p=33586&hilit=dupterm#p33586 add

Code: Select all

from uio import IOBase 
to the import section and change

Code: Select all

class Telnetserver()
into

Code: Select all

class Telnetserver(IOBase)
as shown below in the code snippet:

Code: Select all

import socket
import network
import uos
import errno
from uio import IOBase

last_client_socket = None
server_socket = None

# Provide necessary functions for dupterm and replace telnet control characters that come in.
class TelnetWrapper(IOBase):
    def __init__(self, socket):
        self.socket = socket
        self.discard_count = 0

Jongy
Posts: 9
Joined: Fri Jun 08, 2018 11:50 am

Re: Telnet Server

Post by Jongy » Sat Feb 23, 2019 10:10 pm

Roberthh wrote:
Thu Feb 21, 2019 8:30 pm
The change is simple. According to the hint here viewtopic.php?f=8&t=5868&p=33586&hilit=dupterm#p33586 add

Code: Select all

from uio import IOBase 
to the import section and change

Code: Select all

class Telnetserver()
into

Code: Select all

class Telnetserver(IOBase)
as shown below in the code snippet:

Code: Select all

import socket
import network
import uos
import errno
from uio import IOBase

last_client_socket = None
server_socket = None

# Provide necessary functions for dupterm and replace telnet control characters that come in.
class TelnetWrapper(IOBase):
    def __init__(self, socket):
        self.socket = socket
        self.discard_count = 0

Thanks! That really fixed it.

I was puzzled by this as I didn't realize which magic connects my object with its `write`, `readinto` methods to what `mp_uos_dupterm` accepts. `iobase_read` and `iobase_write` were what I missed...

The `uos.dupterm` should definitely be updated so people won't have to look in the code next time.. :P

Post Reply