Skip to content

Instantly share code, notes, and snippets.

@geekman
Created June 21, 2016 08:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save geekman/b488c6b6df3bc2fccb8cb8e47cc33ff9 to your computer and use it in GitHub Desktop.
Save geekman/b488c6b6df3bc2fccb8cb8e47cc33ff9 to your computer and use it in GitHub Desktop.
automated ESP8266 programming station to mass flash large quantity of devices quickly
#!/usr/bin/env python
#
# automated ESP8266 programming station
# monitors for inserted serial devices and calls esptool to flash them
# written to mass flash entire batches of ESP8266 devices quickly
# $ pip install esptool pyudev
#
# 2016.06.16 darell tan
#
import pyudev
import subprocess
import sys
import os
import time
fwfile = sys.argv[1]
assert os.path.isfile(fwfile)
ctx = pyudev.Context()
mon = pyudev.Monitor.from_netlink(ctx)
mon.filter_by(subsystem='tty')
logf = open('massflash.log', 'a')
devs = {}
print 'waiting for usb events...'
for dev in iter(mon.poll, None):
vid, pid = dev.get('ID_VENDOR_ID', None), dev.get('ID_MODEL_ID', None)
print dev.action, dev.device_node, dev.device_type, \
dev.subsystem, \
vid, pid, \
dev.get('ID_SERIAL', None), dev.get('ID_SERIAL_SHORT', None)
# log in/out times of each device
if dev.action == 'add':
devs[dev] = time.time()
elif dev.action == 'remove':
logf.write('%f %f\n' % (devs.get(dev, -1), time.time()))
# flash device
if dev.action == 'add':
print 'flashing on %s...' % (dev.device_node)
cmd = "esptool.py -b 921600 -p %s write_flash -ff 80m -fs 32m 0x0000 %s" % (dev.device_node, fwfile)
subprocess.Popen(cmd.split())
@Hak4Kidz
Copy link

Hi. This looks great! Has it been tested to work with ESP32 hardware?

@Talles71
Copy link

A M A Z I N G !! Flashing very fast, thank you for this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment