Playing with esptool
/So, where to start? The pytool program is a large chunk of Python that I know nothing about. I know what it does: it takes files off my PC and squirts them into ESP32 and ESP8266 devices. However, I’ve no idea how it works.
Fetching esptool
The good news is that the program source is a free download from here:
https://github.com/espressif/esptool
I used the GitHub desktop tool to clone this and then opened it with Visual Studio code. The first part of my plan is to get it running and then use the Python debugging tools to find out what it does.
Sending a command
The first thing I have to do is get pytool to do something. I settled for just reading the MAC address from a device. I’m using version 3.2 (which is interesting because it came out after the date of this blog post - I’ll leave you to figure out how that works). With this version you can “hard-wire” commands into the program so that it performs them when it starts. You have to find the main function in the Python program and add some arguments. In the version I’m using I found the main function at line 3789 in the esptool.py program file:
def main(argv=[ 'read_mac'], esp=None):
I've added the argument “read_mac”. When I run the program I now get this:
esptool.py v3.2-dev
Found 2 serial ports
Serial port COM12
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: ec:fa:bc:28:56:27
Uploading stub...
Running stub...
Stub running...
MAC: ec:fa:bc:28:56:27
Hard resetting via RTS pin...
The worrying part of this conversation is the message “Uploading stub”, but we’ll get to that later. For now, lets figure out how we can get a JavaScript program to reset a remote device and talk to it over the serial port.