Post:script runs before bits are ready

I have a script to send firmware.hex to an RPi for upload to an Arduino. This script is declared in platformio.ini as

extra_scripts =

Unfortunately it runs before firmware.hex is built, sending the bits from the previous build instead of the current one.

Is there a way to run a script AFTER the bits are ready?

This is correct. Per documentation a post: script runs after the script of the development platform (example) – no firmware has been built yet, but some options are prepared that can be changed.

If you want to act on when the firmware.hex is built, add a Post action for that build project, as documented.


def after_hex_build(source, target, env):
   # custom python logic here 
   # firmware.hex path is str(source[0])

env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", after_hex_build)

If the action is simply another shell command, e.g. scp-ing the file, adapt the Custom HEX from ELF example found in the code linked above.

Thanks Max, that works.