Using BASH script to upload files

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Using BASH script to upload files

Post by iotman » Sat Sep 21, 2019 7:30 pm

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

Online
kevinkk525
Posts: 646
Joined: Sat Feb 03, 2018 7:02 pm

Re: Using BASH script to upload files

Post by kevinkk525 » Sat Sep 21, 2019 8:04 pm

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:

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

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

Re: Using BASH script to upload files

Post by Roberthh » Sat Sep 21, 2019 8:09 pm

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:

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


User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: Using BASH script to upload files

Post by iotman » Sat Sep 21, 2019 9:03 pm

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

User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: Using BASH script to upload files

Post by iotman » Sat Sep 21, 2019 9:26 pm

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

rpr
Posts: 75
Joined: Sat Oct 27, 2018 5:17 pm

Re: Using BASH script to upload files

Post by rpr » Sat Sep 21, 2019 9:46 pm

Does rshell work for you Ok running directly from the linux shell prompt?

User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: Using BASH script to upload files

Post by iotman » Sat Sep 21, 2019 11:53 pm

Hi @rpr, yes, it seems to work fine.

AB

Online
kevinkk525
Posts: 646
Joined: Sat Feb 03, 2018 7:02 pm

Re: Using BASH script to upload files

Post by kevinkk525 » Sun Sep 22, 2019 5:21 am

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

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

Re: Using BASH script to upload files

Post by dhylands » Sun Sep 22, 2019 9:34 pm

No other rshell or terminal program.

User avatar
iotman
Posts: 51
Joined: Sat Feb 02, 2019 4:06 pm
Location: Nanoose Bay, Canada
Contact:

Re: Using BASH script to upload files

Post by iotman » Sun Sep 22, 2019 11:30 pm

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

Post Reply