Basic question about build configurations

Hey all, I’ve got a newb question that I just can’t seem to find an answer for.

I use two boards for my projects, an ESP8266 and an ESP32; and use both USB and OTA for updating.

I’d like to be able to quickly change the build configuration between the 4 possible permutations of the build.

My platformio.ini is below, which doesn’t work as expected. I’d like to be able to select the board and the USB/OTA by changing the default_envs line rather than having to constantly change the board configuration depending on what I’m building.

Thanks!

[platformio]
monitor_speed=115200
default_envs = nodemcuv2,usb

[env:usb]
upload_protocol = esptool

[env:ota]
upload_protocol = espota
upload_port = 192.168.1.100

[env:devkit]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino

The question you should be asking is “How does env:usb and env:ota relate to env:devkit and env:nodemcuv2?” i.e. How does PlatformIO know they are connected?

This isn’t the prettiest, but this is the best I can come up with atm to actually do what you want…

First things first… monitor_speed isn’t a valid option for [platform]… you want that in [env] if it’s a global speed option… and I shoved framework there also since that’s the same for all the boards. Next up, some base level environments (e.g espressif32_base, usb, etc) which can then be used with extends for some creative building up of the actual board environments and save duplication that way. Which then gives:

[platformio]
default_envs = nodemcuv2-usb

[env]
monitor_speed=115200
framework = arduino

[env:espressif32_base]
platform = espressif32

[env:espressif8266_base]
platform = espressif8266

[env:usb]
upload_protocol = esptool

[env:ota]
upload_protocol = espota
upload_port = 192.168.1.100

[env:devkit-ota]
board = esp32doit-devkit-v1
extends = env:espressif32_base, env:ota

[env:devkit-usb]
board = esp32doit-devkit-v1
extends = env:espressif32_base, env:usb

[env:nodemcuv2-ota]
board = nodemcuv2
extends = env:espressif8266_base, env:ota

[env:nodemcuv2-usb]
board = nodemcuv2
extends = env:espressif8266_base, env:usb

If that makes sense, great, otherwise don’t hesitate to ask away! :wink: