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.
Post Reply
AwesomeCronk
Posts: 13
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: 13
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: 115
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: 35
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.

Online
User avatar
pythoncoder
Posts: 4268
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

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

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).

kinno
Posts: 26
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: 13
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.

Post Reply