Automate ESP8266 Programming
From time to time i need to program several hundred ESP-12F modules for my projects. First time i did it, i was changing the module on the programmer and then repeating the command.
However, by doing that it was hard to do programming at several programmers at once and also it required all my attention when the script finished etc.
So i had to automate it a bit, but i didn’t want to throw myself into codding so much. Just the most simple way to do it was an option.
So here we are. The whole solution is just a simple udev rule which sets the programming script to execute. As i said “it sets the script”. Because, udev just triggers and doesn’t handle the runtime environment as when you run a program in terminal. So for that purpose, i used “at now”.
- esptool.py (https://github.com/espressif/esptool/blob/master/esptool.py)
- Install “at” with (apt-get install at)
- Get your firmware.bin and if you need spiffs.bin files
UART programmer, I used this one Frogboard Frogo ESP-12F
** Be careful about the programmer, another one that i was using had very poor construction, i had to hold module by hand and also the button on it was just turning on/off the ESP-12F module not the programmer so i had to plug/unplug the programmer in order to trigger the udev rule. Maybe it was possible to load/unload the module differently but i would make some other problems. **
Set udev rule:
Make file “/etc/udev/rules.d/esptool.rules”
Paste following into the file and change accordingly the path for the script and also check the vendor number for your programmer. You can probably find out more once you plug your device and monitor it like this “udevadm monitor –kernel –property –subsystem-match=usb”
Copy/Paste/Edit the following script with appropriate data and also set it executable by the same user as the one who has esptool.py set in it’s environment.
Feel free to adjust the script according to your needs. There is nothing complex, just simple calling the esptool.py with parameters and passing the output to a log file.
Change [your-user-name] part of the script to your user. The reason was that esptool and the enviromnet was available only for that particular user. I believe it’s gonna be the case with you. The script is initiated by the system so unless you have the env set for root, you would not be able to run the esptool.
The execution is set under the same user so that there is no permission problem when the log is printed.
After you finish, you can grep your logs, catch all MAC addresses in order to track the devices. It would be nice to add some timestamp, maybe even to use esptool.py to burn in your serial into the chip at the same time.
That’s about all.