Page 1 of 2

ESP32-targeted alternative to Ampy

Posted: Thu Apr 09, 2020 8:57 pm
by AwesomeCronk
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.

Re: ESP32-targeted alternative to Ampy

Posted: Thu Apr 09, 2020 9:17 pm
by AwesomeCronk
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.

Re: ESP32-targeted alternative to Ampy

Posted: Fri Apr 10, 2020 8:01 am
by Christian Walther
Have you tried pyboard.py?

Re: ESP32-targeted alternative to Ampy

Posted: Fri Apr 10, 2020 4:35 pm
by cgglzpy
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.

Re: ESP32-targeted alternative to Ampy

Posted: Fri Apr 10, 2020 5:01 pm
by pythoncoder
I recommend rshell. This is an excellent tool for working with all MicroPython targets, including ESP32.

Re: ESP32-targeted alternative to Ampy

Posted: Sun Apr 12, 2020 3:34 pm
by rcolistete
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).

Re: ESP32-targeted alternative to Ampy

Posted: Mon Apr 20, 2020 5:52 pm
by kinno
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.

Re: ESP32-targeted alternative to Ampy

Posted: Fri Jun 26, 2020 7:31 pm
by AwesomeCronk
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.

Re: ESP32-targeted alternative to Ampy

Posted: Sun Jan 24, 2021 4:32 pm
by AwesomeCronk
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.

Re: ESP32-targeted alternative to Ampy

Posted: Sun Jan 24, 2021 8:06 pm
by Roberthh
The mpr tool of Damien is working pretty well. Using that, I do not miss ampy at all.