rshell - Remote Shell

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

Re: rshell - Remote Shell

Post by danielm » Thu Aug 11, 2016 9:12 am

Dave, does rshell support custom telnet port?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell - Remote Shell

Post by dhylands » Thu Aug 11, 2016 3:56 pm

It doesn't look like it.

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

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: rshell - Remote Shell

Post by randmor » Mon May 15, 2017 6:05 pm

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 hello.py /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 'hello.py', 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 hello.py
print("\nMicroPython is cool!\n")

/home/randmor> cp hello.py /flash
Unable to copy '/home/randmor/hello.py' to '/flash'
/home/randmor>

Every time I try to write my source files to "/flash" if fails with the error message "Unable to copy 'whatever.py' 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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell - Remote Shell

Post by dhylands » Mon May 15, 2017 6:40 pm

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.

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

Re: rshell - Remote Shell

Post by Roberthh » Mon May 15, 2017 7:27 pm

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.

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

Re: rshell - Remote Shell

Post by pythoncoder » Tue May 16, 2017 5:24 am

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
flash/
/home/adminpete> ls /pyboard/flash
aremote.py art.py     art1.py    boot.py   
/home/adminpete> ls /flash
aremote.py art.py     art1.py    boot.py   
/home/adminpete> 
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')
['boot.py', 'art.py', 'aremote.py', 'art1.py']
>>> os.listdir('/pyboard/flash')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
>>> 
Peter Hinch
Index to my micropython libraries.

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

Re: rshell - Remote Shell

Post by Roberthh » Tue May 16, 2017 5:40 am

@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: /boot.py /main.py /ftp.py /name_bug.py /sh1106_t.py /ticks_bug.py /disp_f.py /pyboard/boot.py /pyboard/main.py /pyboard/ftp.py /pyboard/name_bug.py /pyboard/sh1106_t.py /pyboard/ticks_bug.py /pyboard/disp_f.py
/home/robert> 
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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: rshell - Remote Shell

Post by dhylands » Tue May 16, 2017 6:58 am

Interesting.

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.

randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

Re: rshell - Remote Shell

Post by randmor » Sat May 27, 2017 4:11 pm

Thanks, Dave Hylands.

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

Code: Select all

/home/randmor> cp hello.py /
Unable to copy '/home/randmor/hello.py' to '//hello.py'
/home/randmor> cp hello.py /flash
Unable to copy '/home/randmor/hello.py' to '/flash/hello.py'
# 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 "hello.py" 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 hello.py /flash
/home/randmor> ls /flash
hello.py
/home/randmor>
 
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

and...

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"
    fi
fi

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

# 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

RSHELL_BUFFER_SIZE="--buffer-size=32"

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?

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

Re: rshell - Remote Shell

Post by Roberthh » Sat May 27, 2017 4:26 pm

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.

Post Reply