Page 3 of 6

Re: rshell - Remote Shell

Posted: Thu Aug 11, 2016 9:12 am
by danielm
Dave, does rshell support custom telnet port?

Re: rshell - Remote Shell

Posted: Thu Aug 11, 2016 3:56 pm
by dhylands
It doesn't look like it.

rshell is built on top of, so you'd need to add support there first so that if rshell did parse the port it would be used.

Re: rshell - Remote Shell

Posted: Mon May 15, 2017 6:05 pm
by randmor
Hi Everyone,

I was wondering if the "rshell" utility program has been tested or used on ESP8266 Boards like the WeMos D1/R1 board? My problem is that I can not copy files from my Ubuntu Linux machine down to the ESP8266 board. I can run "rshell", and I can do the REPL interactive mode all day long, but that gets rather tedious when you want to run more complicated code. I want to be able to download a script from my current working directory in Linux down to the "FAT" file-system on the ESP8266, and then run the script. I can do this under "ampy", but on my Linux system, Terminal (or ampy?) somehow looses control of the serial port (/dev/ttyUSB0) after one use of ampy. Then it's time to reboot Linux to get one more chance.

I have found "rshell" listed as a alternate tool to "ampy" and I am hoping that it works with the ESP8266 file-system. The scant documentation on "rshell" suggests that I can using some command like "cp /flash" to copy my MicroPython source file to the ESP8266 flash memory (3M out of 4M of which are allocated to the ESP8266 FAT file-system). The example also suggests that once the source file is downloaded, that it can be executed by going into the reshell "REPL mode" using the "repl" command, and then executing the downloaded source file using the "import filename" command being careful not to include the .py file extension. So, for '', I should be able to use "import hello" and the MicroPython interpreter on my ESP8266 board should be able to run the script. Sounds clear enough to me. Here is what I have tried to do many times:

/home/randmor> cat
print("\nMicroPython is cool!\n")

/home/randmor> cp /flash
Unable to copy '/home/randmor/' to '/flash'

Every time I try to write my source files to "/flash" if fails with the error message "Unable to copy '' to '/fash'".
So, I am left wondering is there a configuration issue with rshell, or has the label for the file-system in flash memory changed,
or is it that rshell has never been modified to support the ESP8266 file-system?

Any constructive reply from anyone would be most appreciated. Thank you.

Re: rshell - Remote Shell

Posted: Mon May 15, 2017 6:40 pm
by dhylands
I believe that the filesystem on the esp8266 version is just / and not /flash. rhsell currently treats / as part of the host filesystem. The boards command in rshell will show you some virtual alternatives (/pyboard/xxx maps to /xxx on the connected board).

You probably also need to run rshell with --buffer-size=32 (or something similar) since the esp8266 isn't directly connected to USB (but rather goes through a usb-to-serial converter).

I know that there are people using rshell with the esp8266, so hopefully one of them will chime in if there are any other gotchas.

Re: rshell - Remote Shell

Posted: Mon May 15, 2017 7:27 pm
by Roberthh
I just tried again rshell and ESP866 (Wemos D1 Mini), and it worked like you told, Dave

Code: Select all

rshell --buffer-size 32 -p /dev/ttyUSB0
The files on the ESP8266 are available under /pyboard/xxxx. I can copy in & out files, edit them, and start repl and leave it.
Only the boards command responds a little bit strange, considering every file as dir.

Re: rshell - Remote Shell

Posted: Tue May 16, 2017 5:24 am
by pythoncoder
It works fine for me too. I use the following alias

Code: Select all

alias rsusb='rshell -p /dev/ttyUSB0 --editor nano --buffer-size=30'
It can take a few seconds to connect but as far as I can see it works fine - @Robert-hh I'm not sure what you mean by each file being a directory. I can see the same (correct) filesystem under /flash and (to my surprise) also under /pyboard/flash.

Code: Select all

/home/adminpete> ls /pyboard
/home/adminpete> ls /pyboard/flash   
/home/adminpete> ls /flash   
At the REPL the filesystem is under /flash only (as I'd expect):

Code: Select all

/home/adminpete> repl
Entering REPL. Use Control-X to exit.
MicroPython v1.8.7-456-ge402c51 on 2017-03-21; ESP module with ESP8266
Type "help()" for more information.
>>> import os
>>> os.listdir('/flash')
['', '', '', '']
>>> os.listdir('/pyboard/flash')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV

Re: rshell - Remote Shell

Posted: Tue May 16, 2017 5:40 am
by Roberthh
@pythoncode: In rshell, just issue the boards command. I get the following:

Code: Select all

Welcome to rshell. Use Control-D to exit.
/home/robert> boards
pyboard @ /dev/ttyUSB0 connected Dirs: / / / / / / / /pyboard/ /pyboard/ /pyboard/ /pyboard/ /pyboard/ /pyboard/ /pyboard/
And in the most recent version of the ESP8266 firmware, the file system in flash is again by default mounted at /. It was mounted on /flash for a while.

Re: rshell - Remote Shell

Posted: Tue May 16, 2017 6:58 am
by dhylands

When I wrote rshell, I never considered the case where the root directory of a filesystem would be /

The esp8266 didn't exist, and the pyboard has /flash and /sd

Currently, the boards command assumes that each item returned in / is the directory name of a filesystem, so on the pyboard, os.listdir('/') returns /flash and optionally /sd.

Now that everything is using the new VFS, rshell should really query the mount table to determine the mount points.

Re: rshell - Remote Shell

Posted: Sat May 27, 2017 4:11 pm
by randmor
Thanks, Dave Hylands.

Your suggestion of using the "--buffer-size=32" setting when invoking "rshell" definitely helped the situation. But copying my "" test file to "/" or "/flash" directories still did not work. Here are my results:

Code: Select all

/home/randmor> cp /
Unable to copy '/home/randmor/' to '//'
/home/randmor> cp /flash
Unable to copy '/home/randmor/' to '/flash/'
# Note the double slashes in the first response. Is that a bug or clue?

However, I found that if I go into "repl", I can use the command "vfs.mkdir('flash')" to create the "/flash" directory in the ESP8266 file system, and then after I restart "rshell", I can use "cp" to copy my files into the "/flash" directory okay. But, it seems to me there may be a bug in "rshell" such that it can not recognize new directories created in REPL using the "vfs.mkdir()" until after you restart "rshell" (again using the "--buffer-size=32" setting).

Here are my results of copying my "" file to "/flash" after pre-creating a "/flash" directory and restarting "rshell" with the "--buffer-size=32" setting specified:

Code: Select all

/home/randmor> cp /flash
/home/randmor> ls /flash
So, pre-create your "/flash" directory on the ESP8266 file system using "repl" mode and the "vfs.mkdir('flash')" command, then restart "rshell" with the "--buffer-size=32" setting. When "rshell" comes up you can use the "cp" command to copy files to "/flash" or other directories which you have pre-created. It seems to work pretty well, and you can use the other vfs commands (use "dir(vfs)" to get a list of them). I'm pretty happy with "rshell" now, and I can now put away "mpy-upload" utility which was my work-around for this problem until I discovered the real fix:

rshell --port /dev/ttyUSB0 --buffer-size=32


pre-creating your directories using the "vfs.mkdir('dirname')" repl command


Now I am wondering if there is an Environment variable we can use to remember the "reshell" "--buffer-size=32" setting in the way that we do for the "--port /dev/ttyUSB0" setting?

For anyone reading this, here is my Linux .profile file which you can use to specify environment variables and other startup scripts so that when you login you don't have to re-enter them. If all the optional parameters can be specified using environment variables, then you can start up "rshell" by just typing "rshell", not the long form of "rshell --port /dev/ttyUSB0 --buffer-size=32". Here's a listing of my .profile file which is kept in my "/home/randmor" directory:

Code: Select all

# ~/.profile: Executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.
# See /usr/share/doc/bash/examples/startup-files for examples.
# The files are located in the bash-doc package.

# The default umask is set in /etc/profile; for setting the umask
# For ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

# Set up environment variable "AMPY_PORT" so you don't have to
#  specify the serial port "path" every time you use the "ampy" command.
export AMPY_PORT="/dev/ttyUSB0"

# Set up environment variable "RSHELL_PORT" so you don't have to
#  specify the serial port "path" every time you use "rshell".
export RSHELL_PORT="/dev/ttyUSB0"

What I am hoping for is something like


When I tried it, after restarting Linux and entering just "rshell" I got into "rshell" okay, but when I went to copy a file to the "/flash" directory in the ESP8266 file-system, it just closed my serial port:

Code: Select all

(trusty)randmor@localhost:~$ rshell
Connecting to /dev/ttyUSB0 ...
Welcome to rshell. Use Control-D to exit.
/home/randmor> cp .profile profile.txt
/home/randmor> cp profile.txt /flash
serial port /dev/ttyUSB0 closed
Any suggestion?

Re: rshell - Remote Shell

Posted: Sat May 27, 2017 4:26 pm
by Roberthh
As discussed before, "/" is the top level directory on you local computer. The top level directory on the micropython device can alway be accessed under the path "/pyboard", even if that directory does not exist.
As for a convenient start of rshell with the requested parameters you may use an alias like suggested by @pythoncoder above.