Skip to content

Instantly share code, notes, and snippets.

@atomi
Forked from geekman/massflash.py
Created October 16, 2017 18:30
Show Gist options
  • Save atomi/8ddbf1f024cefe3f69d53a276177a4df to your computer and use it in GitHub Desktop.
Save atomi/8ddbf1f024cefe3f69d53a276177a4df 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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment