ESP32-targeted alternative to Ampy

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.
AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

ESP32-targeted alternative to Ampy

Post by AwesomeCronk » Thu Apr 09, 2020 8:57 pm

I want to make a command-line tool to share files between my PC and my HUZZAH32. I found Adafruit's Ampy tool, which sometimes works, but most of the time doesn't. In order to change anything, I have to stop the device from PuTTy, then write an empty file into boot.py using the REPL, then modify other files as needed with Ampy, then write boot.py back into the device with Ampy.

For rapid development, this is painful. In order to find out what was going on, I downloaded the ampy source code (YAY OPEN SOURCE!!!!) and found that it was written to work with the PyBoard. Cool. What I want to do is find or write an alternative to the Ampy tool that is capable to stopping execution of whatever script may be running on the device, then entering raw REPL, reading/writing the appropriate files, and rebooting if desired.

I took a crack at this using the Serial module in Python (big python on my PC) to talk to the device, but could not issue even a basic print command to the device. At that point, I was just writing to the standard REPL like PuTTy does, but that didn't work. I will be doing some research in raw REPL and see what I can do about this whole deal.

I will post replies to this thread as development advances.

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: ESP32-targeted alternative to Ampy

Post by AwesomeCronk » Thu Apr 09, 2020 9:17 pm

I have changed the way I read from the serial port this time. At this point, I can read the boot-up data spit out by the ESP32 and I can see the REPL prompt. Issueing a command has been successful.

Code: Select all

import serial
serialPort = serial.Serial(
                           port = "COM3",
                           baudrate = 115200,
                           bytesize = 8,
                           timeout = 2,
                           stopbits = serial.STOPBITS_ONE
                          )

test = True

while(True):
    if serialPort.in_waiting > 0:
        sString = serialPort.readline()
        print('DEVICE: {}'.format(sString))
        if sString == b'>>> ':
            print('HOST: Identfied REPL prompt.')
            if test:
                serialPort.write(b"print('hello world!')\r\n")
                test = False
A bit of web searching reveals b"\x03" to be the byte to send to the device for Ctrl+C. I am now writing code to share files.

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: ESP32-targeted alternative to Ampy

Post by Christian Walther » Fri Apr 10, 2020 8:01 am

Have you tried pyboard.py?

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: ESP32-targeted alternative to Ampy

Post by cgglzpy » Fri Apr 10, 2020 4:35 pm

Hi AwesomeCronk, you may be interested to have a look at upydev and upydevice , a CLI and a python library which I made to meet these needs.

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

Re: ESP32-targeted alternative to Ampy

Post by pythoncoder » Fri Apr 10, 2020 5:01 pm

I recommend rshell. This is an excellent tool for working with all MicroPython targets, including ESP32.
Peter Hinch
Index to my micropython libraries.

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: ESP32-targeted alternative to Ampy

Post by rcolistete » Sun Apr 12, 2020 3:34 pm

I also recommend mpfshell, it works in some cases where rshell doesn't connect, like Atom Lite/Matrix (ESP32 boards) running UIFlow 1.4.5/1.4.5.1 (MicroPython modified by M5Stack).
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

kinno
Posts: 32
Joined: Mon Oct 21, 2019 2:06 pm

Re: ESP32-targeted alternative to Ampy

Post by kinno » Mon Apr 20, 2020 5:52 pm

To add to this.

If you are using multiple boards from different vendors, revisions etc. I think rshell is most stable with MPF shell being a close second.

I personally like MPF shell because less keystrokes but it does not always connect to my ESP32's where rshell will.

I recommend having both on your system.

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: ESP32-targeted alternative to Ampy

Post by AwesomeCronk » Fri Jun 26, 2020 7:31 pm

To everyone who commented here, I'm sorry for not getting back to you sooner. I apparently have notifications turned off. I looked through those tools just now and I really like some of them. I am, however, going to continue working on uPyFile, if only to complete it. I will definitely spend more time reading about some of these, especially rshell and uPydev/uPydevice. As it stands, I have managed to get uPyFile to where it can send files. As I have been unable to figure out the raw REPL so far, I have been packing the file data into uPython code and then sending that. This way, what the device sees is a terminal reset, followed by this input:

Code: Select all

file = open('test.txt', 'wb')
file.write(b'Hello world!')
file.close()
I have also written a batch script which calls PyInstaller and then moves the resulting package to a specified location. I plan to write an accompanying bash script to do the same for Linux and Mac users. The code can be found at https://github.com/AwesomeCronk/uPyFile.

AwesomeCronk
Posts: 33
Joined: Fri Oct 11, 2019 1:24 am

Re: ESP32-targeted alternative to Ampy

Post by AwesomeCronk » Sun Jan 24, 2021 4:32 pm

Update on the project: uPyFile is pretty much finished. It can read files from the device, list directories, and push/pull files to and from the device and computer. I have tested it on a HUZZAH32 and an ESP32-CAM. It is definitely ready for use.

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

Re: ESP32-targeted alternative to Ampy

Post by Roberthh » Sun Jan 24, 2021 8:06 pm

The mpr tool of Damien is working pretty well. Using that, I do not miss ampy at all.

Post Reply