Using BASH script to upload files
Using BASH script to upload files
Hi, I'm trying to create a BASH script on my Ubuntu machine that will upload a file set to an ESP32 running MicroPython.
I'm having a problem with AMPY in that it will only execute a single command. After that, when I try to execute another command (like PUT), it fails with the "cannot enter repl mode" error. Adafruit no longer supports it, unfortunately - they are off in the CircuitPython direction, but I prefer MP. I have tried setting delays, etc.
But it seems to be the only choice that can be used from within a BASH script. I tried to use rshell, but that does not seem to work from within a BASH script. I have already automated the Micropython installation using ESPTOOL from inside a BASH script - that worked really well.
So I have some general questions:
1. Is there a better way to install Micropython and upload a file set that includes sub-directories? Maybe something else besides BASH?
2. Does anyone know how to use AMPY to upload all root files and sub-folders with a single command?
Just to be clear, the overview is that I'm trying to erase the flash, install MP, then upload all files, including sub-directories, with a single command on my laptop (through a USB connection to the ESP32).
Tks, AB
I'm having a problem with AMPY in that it will only execute a single command. After that, when I try to execute another command (like PUT), it fails with the "cannot enter repl mode" error. Adafruit no longer supports it, unfortunately - they are off in the CircuitPython direction, but I prefer MP. I have tried setting delays, etc.
But it seems to be the only choice that can be used from within a BASH script. I tried to use rshell, but that does not seem to work from within a BASH script. I have already automated the Micropython installation using ESPTOOL from inside a BASH script - that worked really well.
So I have some general questions:
1. Is there a better way to install Micropython and upload a file set that includes sub-directories? Maybe something else besides BASH?
2. Does anyone know how to use AMPY to upload all root files and sub-folders with a single command?
Just to be clear, the overview is that I'm trying to erase the flash, install MP, then upload all files, including sub-directories, with a single command on my laptop (through a USB connection to the ESP32).
Tks, AB
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Using BASH script to upload files
I use rshell from bash and have no problem. What is your problem with rshell in a bash script?
This is part of my bash script:
This is part of my bash script:
Code: Select all
#!/bin/bash
rshell -p /dev/ttyS3 "cp config.py /pyboard/;cp boot.py /pyboard/;cp main.py /pyboard/"
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Using BASH script to upload files
You could try pyboard.py https://github.com/micropython/micropyt ... pyboard.py, which is the heart of rshell. The new version supports file copy. Just call pyboard.py --help for usage hints.
The commit hat the following message:
The commit hat the following message:
Code: Select all
Author: Damien George <damien.p.george@gmail.com>
Date: Wed Jul 10 16:48:37 2019 +1000
tools/pyboard.py: Add filesystem commands to ls/cat/cp/rm remote files.
Use "-f" to select filesystem mode, followed by the command to execute.
Optionally put ":" at the start of a filename to indicate that it's on the
remote device, if it would otherwise be ambiguous.
Examples:
$ pyboard.py -f ls
$ pyboard.py -f cat main.py
$ pyboard.py -f cp :main.py . # get from device
$ pyboard.py -f cp main.py : # put to device
$ pyboard.py -f rm main.py
Re: Using BASH script to upload files
Hi, wow, 2 great answers, thanks very much - this is so helpful.
It looks like I was using rshell with the wrong syntax, so I'll try that again.
Pyboard is new to me, so I will definitely check that out. I didn't realize there was something built into MP that could actually upload files.
Cheers, AB
It looks like I was using rshell with the wrong syntax, so I'll try that again.
Pyboard is new to me, so I will definitely check that out. I didn't realize there was something built into MP that could actually upload files.
Cheers, AB
Re: Using BASH script to upload files
Hi @kevinkk525, I tried that line of code you provided in my BASH script, but it just hung with "Trying to connect to REPL", so I'm wondering if there is anything else that needs to precede the line of code that actually uploads the files?
Tks, AB
Tks, AB
Re: Using BASH script to upload files
Does rshell work for you Ok running directly from the linux shell prompt?
Re: Using BASH script to upload files
Hi @rpr, yes, it seems to work fine.
AB
AB
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Using BASH script to upload files
If it hangs on connect then I am not sure what the problem is. It should just work like when using it directly in the console. Just make sure no other rshell is connected to your board otherwise it will hang on connect.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Using BASH script to upload files
Hi, ok, thanks muchly for all the feedback. It seems I am getting unexpected results, so I'm going to re-flash MicroPython on the ESP32, reboot everything, and start over. Hopefully this will eliminate any extraneous system issues I may be experiencing.
Tks All, AB
Tks All, AB