2PlatformIO extra_script: make ``pio run -t upload`` push over Ethernet.
4Adapted from maxgerhardt/pio-esp32-ethernet-ota, which replaces UPLOADCMD with
5a custom command — the idea being that OTA should be the same one-button
6action as a USB upload, not a separate script you have to remember. The
7difference here is that it drives ``ota_upload.py`` (our own protocol and our
8own error messages) rather than curl.
10Wire it into any project by adding an OTA env to its platformio.ini:
13 extends = env:adafruit_feather_esp32s3 ; your normal build env
14 upload_protocol = custom
15 extra_scripts = post:../../tools/pio_ota_upload.py ; adjust depth
21 pio run -e ota -t upload
23``upload_flags`` are passed straight through to ota_upload.py, so anything it
24accepts works here — e.g. ``--port=3232`` or a longer ``--timeout=90``.
26The path depth differs per project (the repo's projects sit at different
27levels), which is why this is spelled out per project rather than in
28platformio-common.ini — the same reason lib_extra_dirs is per-project there.
43 _THIS_FILE = sys._getframe().f_code.co_filename
45_TOOLS_DIR = os.path.dirname(os.path.abspath(_THIS_FILE))
46_UPLOADER = os.path.join(_TOOLS_DIR,
"ota_upload.py")
50 """Run ota_upload.py against the just-built firmware.bin."""
51 firmware = str(source[0])
57 flags = [str(f)
for f
in env.subst_list(
"$UPLOADERFLAGS")[0]]
59 if not any(str(f).startswith(
"--ip")
for f
in flags):
61 "[OTA] ERROR: no --ip in upload_flags. Add e.g.\n"
63 " --ip=192.168.2.41\n"
64 " to this environment in platformio.ini."
69 cmd = [sys.executable, _UPLOADER,
"--bin", firmware] + [str(f)
for f
in flags]
70 print(
"[OTA] " +
" ".join(cmd))
72 env.VerboseAction(
" ".join(f
'"{c}"' for c
in cmd),
"Uploading over Ethernet")
78env.Replace(UPLOADCMD=_on_upload)
_on_upload(source, target, env)