rshell error in handling file system

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

rshell error in handling file system

Post by manos » Tue Nov 10, 2020 9:19 pm

Hey everyone,

I have just installed (newbie here) rshell in my xubuntu and I am trying to interact with my Xbee 3.
After some trials, I have managed to enter the Micropython REPL of my xbee successfully - so I guess the serial communication is working fine.
But, whenever I try to, let's say, list the files of /flash, I get the following error:

Traceback (most recent call last):
File "/usr/local/bin/rshell", line 9, in <module>
load_entry_point('rshell==0.0.28', 'console_scripts', 'rshell')()
File "/usr/local/lib/python3.7/dist-packages/rshell/command_line.py", line 4, in main
rshell.main.main()
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 2966, in main
real_main()
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 2949, in real_main
shell.cmdloop(cmd_line)
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 1755, in cmdloop
cmd.Cmd.cmdloop(self)
File "/usr/lib/python3.7/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 1785, in onecmd
self.onecmd_exec("".join(group))
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 1796, in onecmd_exec
return cmd.Cmd.onecmd(self, line)
File "/usr/lib/python3.7/cmd.py", line 217, in onecmd
return func(arg)
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 2401, in do_ls
stat = auto(get_stat, filename)
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 588, in auto
return dev.remote_eval(func, dev_filename, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/rshell/main.py", line 1515, in remote_eval
return eval(self.remote(func, *args, **kwargs))
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing

Any ideas/solutions?
Thanks in advance!

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

Re: rshell error in handling file system

Post by dhylands » Tue Nov 10, 2020 9:28 pm

Hmm. That's a little unexpected.

Perhaps the xbee's don't have a /flash?

What does the output of the

Code: Select all

boards
command? This should show the available filesystems.

You could also try using os.listdir('/') from the REPL.

manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Re: rshell error in handling file system

Post by manos » Tue Nov 10, 2020 11:07 pm

Thank you dhylands for your reply!!

No, xbee's have /flash, that's for sure.
Boards returns:
pyboard @ /dev/ttyUSB0 connected Epoch: 2000 Dirs: /flash /pyboard/flash
Also, I tried:
rshell -p /dev/ttyUSB0 -b 9600 ls /pyboard/flash
but I had similar result.

The os.listdir() works, but the thing is that I was hoping I would be able to use rshell to handle the file system.
In particular, I was hoping I will be able to transfer files from the host pc to my xbee and/or delete files from the flash of my xbee.
It seems, that with that error (which is fatal as it crashes rshell) in whatever command concerns the file system, I won't be able to achieve this...

May I also ask about the way rshell remove files from the flash? This might be a totally wrong question, but I am still a newbie (excuse my ignorance).
I have noticed that by using os.remove the file is not listed anymore in os.listdir but the size of flash once occupied by the aforementioned file is not freed...So, I was wondering if rshell is utilizing os.remove or not?

Thank you again!

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

Re: rshell error in handling file system

Post by dhylands » Tue Nov 10, 2020 11:22 pm

Fundamentally, rshell just uses python calls. So to remove a file, it calls os.remove(filename): https://github.com/dhylands/rshell/blob ... in.py#L835

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

Re: rshell error in handling file system

Post by dhylands » Tue Nov 10, 2020 11:28 pm

rshell relies on the RAW REPL so if the raw repl doesn't work properly on your board, then rshell won't be able to do anything.

You might also want to try pyboard.py: https://github.com/micropython/micropyt ... pyboard.py

Using the -f option you can do cp, rm, ls, car, mkdir, rmdir

Note that pyboard.py also relies on the RAW REPL, so it may not work if the raw repl doesn't work on the xbee.

manos
Posts: 27
Joined: Mon Sep 28, 2020 9:03 am

Re: rshell error in handling file system

Post by manos » Wed Nov 11, 2020 8:50 am

Thank you for your information!

Well, if I understood correctly, you believe that this might be a problem of the REPL?
Meaning that in (my) xbee the os command is not working properly?
If so, is there anything that I can do in order to:
1) check that is REPL's fault
2) overcome this problem somehow

I am currently checking pyboard tool (although I have some troubles installing the mpr), but I am afraid that if neither rshell is working nor ampy then luck is not by my side.

Lastly, is there by any chance any suggestion about an alternative way to (finally) manage to delete the files from the flash?
If all fails through micropython's modules, I was thinking of trying and writing a c module that would access and handle the flash itself but I am not pretty sure if this would work. Not to say that I am not pretty sure about how to do it. Do you think this could be a solution and if so, maybe you could suggest me any guidelines or point me to some tutorials or something?
[edit: I finally managed to delete flash files properly, by updating the firmware and then importing uos and running uos.remove("file_name")]

Thanks in advance
Last edited by manos on Wed Nov 11, 2020 2:12 pm, edited 1 time in total.

User avatar
aivarannamaa
Posts: 171
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: rshell error in handling file system

Post by aivarannamaa » Wed Nov 11, 2020 11:47 am

@manos, please check whether you can access files with Thonny IDE (https://github.com/thonny/thonny/releases/tag/v3.3.0b7):

* Once you have installed and launched Thonny, click on the lower-right corner of the window and select MicroPython back-end
* Select "View => Files"
* Upload/download commands are available when you right-click on the files
Aivar Annamaa
https://thonny.org

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

Re: rshell error in handling file system

Post by pythoncoder » Thu Nov 12, 2020 9:19 am

@manos I would check that the raw REPL is working on your port. If you hit ctrl-a at the REPL you should get this response:

Code: Select all

>>>  <ctrl-a pressed here>
raw REPL; CTRL-B to exit
> <ctrl-b pressed here>
MicroPython v1.13-107-g18518e26a-dirty on 2020-11-12; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
Regarding deleting files and reported flash space this is rather involved and may depend on the filesystem. At the physical level flash stores data in blocks. Blocks can only be rewritten if they are erased first*. So there are at least two questions here:
  • Does the block get erased when the file using it is deleted, when the space it occupies is required, or at some other time? Erasure is a slow process.
  • Do blocks that are mapped out of the filesystem but are not yet physically erased count towards reported free space?
I don't know the answer to these questions for MicroPython but it doesn't surprise me if free space is not immediately updated.

*This is a simplification but it's broadly true.
Peter Hinch
Index to my micropython libraries.

Post Reply