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.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: rshell - Remote Shell

Post by pythoncoder » Sat Dec 23, 2017 6:45 pm

OK. I use rshell on ESP32 running the official build without issue. I use --buffer-size=30 -a. If you try this and it doesn't work it must be a peculiarity of the Loboris port.
Peter Hinch
Index to my micropython libraries.

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: rshell - Remote Shell

Post by slzatz » Sat Dec 23, 2017 10:21 pm

Thanks for the suggestion but unfortunately adding -a did not work so could be the port or something about my host setup.

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: rshell - Remote Shell

Post by loboris » Sat Dec 30, 2017 9:42 am

slzatz wrote:
Sat Dec 23, 2017 1:23 am
I am using the @loboris micropython ESP32 port and am running rshell on ubuntu 17.10. I start rshell with:
...
Anyone seen this and have any suggestions?

I can't reproduce this, running on Ubuntu 17.10, latest MicroPython from repository on ESP-WROVER-KIT v3:
rshell installed with pip3.

Code: Select all

boris@UbuntuMate:/home/LoBo2_Razno/ESP32/MicroPython/test/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD$ rshell -p /dev/ttyUSB1
Connecting to /dev/ttyUSB1 ...
Welcome to rshell. Use Control-D to exit.
/home/LoBo2_Razno/ESP32/MicroPython/test/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD> ls
build/             firmware/          BUILD.sh           partitions_mpy.csv sdkconfig.defaults
components/        main/              Makefile           sdkconfig          sdkconfig.old     
/home/LoBo2_Razno/ESP32/MicroPython/test/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD> ls /flash
boot.py
/home/LoBo2_Razno/ESP32/MicroPython/test/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD> ls /pyboard
flash/
/home/LoBo2_Razno/ESP32/MicroPython/test/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD> 
/home/LoBo2_Razno/ESP32/MicroPython/test/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD> repl
Entering REPL. Use Control-X to exit.
>
MicroPython ESP32_LoBo_v2.0.8 - 2017-11-04 on ESP32 board with ESP32
Type "help()" for more information.
>>> 
>>> import os
>>> os.stat("/")
(16384, 0, 0, 0, 0, 0, 0, 0, 0, 0)
>>> os.stat("/flash")
(16384, 0, 0, 0, 0, 0, 999424, 946684800, 946684800, 946684800)
>>>  

slzatz
Posts: 92
Joined: Mon Feb 09, 2015 1:09 am

Re: rshell - Remote Shell

Post by slzatz » Sat Dec 30, 2017 8:31 pm

Just to close the loop on my issue with rshell and the @loboris port -- I hadn't pulled the latest firmware and was testing rshell with:

Code: Select all

MicroPython ESP32_LoBo_v2.0.7 - 2017-11-01 on ESP32 board with ESP32
when I updated to

Code: Select all

MicroPython ESP32_LoBo_v2.0.8 - 2017-11-04 on ESP32 board with ESP32
os.stat("/flash") and rshell work fine. Sorry for the noise.

seonr
Posts: 43
Joined: Mon Sep 10, 2018 6:54 am

Re: rshell - Remote Shell

Post by seonr » Fri Jan 25, 2019 4:16 am

Excuse my Python and MicroPython ignorance... super new to all of this... but I have a question about using rshell inside some python code to talk to and issue commands to my ESP32 board.

I have this all working atm using subprocess and using commands like...

Code: Select all

cmd = "rshell -p /dev/ttyUSB0 -f rshell_tests"; 
result = "done" in str(subprocess.check_output(cmd, shell = True ))
where rshell_tests is a list of commands that copies MP code to the ESP32 and then runs it via repl... example:

Code: Select all

cp doit_tests.py /pyboard/tests.py
cp micropython_dotstar.py /pyboard/micropython_dotstar.py
repl ~ import tests ~ tests.TestIO() ~
echo "done"
I do stuff like this a few times.... it's a flashing and testing jig for my TinyPICO boards

it's working great as is, BUT it's slow... each time I do a shell call with

Code: Select all

cmd = "rshell -p /dev/ttyUSB0 xxxxxxxxx
I get hit with the connection time it takes to get to the board :( I know that doesn't sound too bad, but every second I can shave off the flash/test cycle is super important on a PCB Assembly line.

What I'd really like to do is use rshell directly in my python code, where I can create a connection, and hold it open for all of the tests and stuff I want to do and then at the end, close it... something like

Code: Select all

conn = rshell.connect( dev/ttyUSB0 )
conn.command("repl ~ xxxxxxx")
# wait a bit
conn.command("repl ~ yyyyyyy")
# do other stuff
conn.close()
Is something like this possible? I have tried importing rshell to see what I have access to, but nothing pops out as being usable like this.

UPDATE:
So rshell.main has a bunch of stuff in it and I've tried this...

Code: Select all

from rshell import main
conn = main.connect_serial("/dev/ttyUSB0")
but I get the following error

Code: Select all

Connecting to /dev/ttyUSB0 ...
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    conn = main.connect_serial("/dev/ttyUSB0")
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1227, in connect_serial
    dev = DeviceSerial(port, baud, wait)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1473, in __init__
    Device.__init__(self, pyb)
  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1275, in __init__
    if not BINARY_XFER:
NameError: name 'BINARY_XFER' is not defined
Thanks

Seon
unexpectedmaker.com

seonr
Posts: 43
Joined: Mon Sep 10, 2018 6:54 am

Re: rshell - Remote Shell

Post by seonr » Fri Jan 25, 2019 6:19 am

I got a bit further...

Code: Select all

from rshell import main
main.main()
conn = main.connect_serial("/dev/ttyUSB0")
print ( "Num devices: " + str(main.num_devices()))
But this is putting me into rshell in terminal... and doesn't do any connection until I hit CTRL+D to exit, then it shows it connecting and prints 1 for devices and then quits :(

I'm sure I'm missing something simple here... but I honestly have no idea what I am doing ;)

Seon
unexpectedmaker.com

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

Re: rshell - Remote Shell

Post by Roberthh » Fri Jan 25, 2019 6:37 am

Internally, rshell (and ampy) uses pyboard.py (https://github.com/micropython/micropyt ... pyboard.py) for it's magic. So you might look at that and how rshell (or ampy) use that.

seonr
Posts: 43
Joined: Mon Sep 10, 2018 6:54 am

Re: rshell - Remote Shell

Post by seonr » Fri Jan 25, 2019 8:13 am

Roberthh wrote:
Fri Jan 25, 2019 6:37 am
Internally, rshell (and ampy) uses pyboard.py (https://github.com/micropython/micropyt ... pyboard.py) for it's magic. So you might look at that and how rshell (or ampy) use that.
Thanks Roberthh :-)

So I've managed to get it to run some MP code via RELP using this

Code: Select all

from rshell import main
from rshell import pyboard

main.main()
main.connect_serial("/dev/ttyUSB0")
print ( "Num devices: " + str(main.num_devices()))

pyb = pyboard.Pyboard('/dev/ttyUSB0')

pyb.enter_raw_repl()
pyb.exec("from machine import SPI, Pin")
pyb.exec("from micropython_dotstar import DotStar")
pyb.exec("import network, time, micropython")
pyb.exec("spi = SPI(sck=Pin(12), mosi=Pin(13), miso=Pin(18))")
pyb.exec("dotstar = DotStar(spi, 1)")
pyb.exec("dotstar[0] = (255, 0, 255, 1)")
pyb.exit_raw_repl()
But it loads rshell and then sits there doing nothing, saying no boards are connected... I need to hit CTRL+D to quit for the code beyond

Code: Select all

main.main()
to run.

I've tried calling main.autoconnect() before main.main() but that doesn't do anything either.

Calling main.main() tells me there is no board connected, so puts me to the rshell prompt telling me to type connect...

Any idea how I tell it what the board is before I call main.main() ?

I've tried creating a Device() by passing in the pyb but that fails in the same place calling connect before main() fails... with this..

Code: Select all

  File "/usr/local/lib/python3.5/dist-packages/rshell/main.py", line 1275, in __init__
    if not BINARY_XFER:
NameError: name 'BINARY_XFER' is not defined
Which clearly means main() has to be called first.

And I can't seem to find a way and I can't call main.connect_serial() until after I call main.main().

Thanks,

Seon
unexpectedmaker.com

seonr
Posts: 43
Joined: Mon Sep 10, 2018 6:54 am

Re: rshell - Remote Shell

Post by seonr » Fri Jan 25, 2019 10:55 am

Ok, I got it connecting in min.main() by pre-setting the default port in the env

Code: Select all

from rshell import main
from rshell import pyboard
import os

os.environ['RSHELL_PORT'] = "/dev/ttyUSB0"
main.main()

print ( "Num devices: " + str(main.num_devices()))
But it still stops at the rshell command prompt after connecting to /dev/ttyUSB0 and doesn't execute the rest of the code until I quit rshell with CTRL+D

Anyone with any ideas?

Seon
unexpectedmaker.com

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

Re: rshell - Remote Shell

Post by pythoncoder » Fri Jan 25, 2019 1:14 pm

I think @Roberthh is right: pyboard.py is your way forward. rshell is a command line utility and is not really intended to be imported into Python code.

You might like to look at run-tests which is the Python script for running the MicroPython test suite. This enables tests to be run on the Pyboard using pyboard.py.
Peter Hinch
Index to my micropython libraries.

Post Reply