I was able to use the extra_script parameter to be able to run a script before building but is there a way to run a script before and after uploading firmware? There are some files that I want removed before building the SPIFFS image but I want to add them back after it has successfully uploaded.
Implemented in
See example Redirecting...
platformio.ini
[env:pre_and_post_hooks]
extra_script = extra_script.py
extra_script.py
Import("env")
def before_upload(source, target, env):
print "before_upload"
# do some actions
def after_upload(source, target, env):
print "after_upload"
# do some actions
env.AddPreAction("upload", before_upload)
env.AddPostAction("upload", after_upload)
Result
...
Processing .pioenvs/uno/libFrameworkArduino.a
Processing .pioenvs/uno/firmware.elf
Check program size...
text data bss dec hex filename
1618 16 166 1800 708 .pioenvs/uno/firmware.elf
Processing .pioenvs/uno/firmware.hex
Processing upload
before_upload
Looking for upload port/disk...
Auto-detected: /dev/cu.usbmodemFD131
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: reading input file ".pioenvs/uno/firmware.hex"
avrdude: writing flash (1634 bytes):
Writing | ################################################## | 100% 0.27s
avrdude: 1634 bytes of flash written
avrdude: verifying flash memory against .pioenvs/uno/firmware.hex:
avrdude: load data flash data from input file .pioenvs/uno/firmware.hex:
avrdude: input file .pioenvs/uno/firmware.hex contains 1634 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.21s
avrdude: verifying ...
avrdude: 1634 bytes of flash verified
avrdude: safemode: Fuses OK (H:00, E:00, L:00)
avrdude done. Thank you.
after_upload
================== [SUCCESS] Took 3.12 seconds ==============
Great! Thanks for the info. That should do the trick!