PlatformIO Community

Cannot replace config variables using advanced scripting


I was trying to conditionally replace some variables inside platformio.ini using a python script registered as a pre extra script: extra_scripts = pre:scripts/

When I try to do config.set('common', 'esp_protocol', 'esptool') inside that script, even though print(config.get('common', 'esp_protocol')) returns the expected ‘esptool’ string, I still get Warning! Unknown upload protocol ESP_PROTOCOL, where that’s defined as `esp_protocol = ESP_PROTOCOL’ inside platformio.ini.

Relevant scripts can be found here
I’m using platformio core 5.0.4.

If anyone knows why this maybe happening and how I can fix it, please let me know.


Seems the evaluation of upload_protocol = ${common.esp_protocol} is done at the time when esp_protocol = ESP_PROTOCOL thus leading to Warning! Unknown upload protocol ESP_PROTOCOL.

Have you tried to modify the script to set env["UPLOAD_PROTOCOL"] = "esptool" directly while removing the upload_protocol = .. line the platformio.ini?

Hi, thanks for the reply. That solution does seem to work, however the way I have this set up I’m trying to support a range of platforms such as espressif and arduino which have their own upload tool, and so using this global upload protocol setting wouldn’t be easy to work with. I’m not too familiar with platformio scripting, but I’m wondering if it’s possible to specify a specific environment for the upload protocol, such as if I defined [env:espressif]?

In the python script you can still interrogate env["PIOPLATFORM"], that will give you e.g. espressif32 or atmelavr and you can act on that, so it’s not global for all environments.

You can also create multiple environments for one board wich only differ in the upload protocol.

The way I’d do it is to just put commented-out lines and comments in the platformio.ini to have the user know how to select a different upload method.

Or I’ve misunderstood the question.