How to handle both OTA and serial upload in platformio.ini
When you’re writing a PlatformIO firmware that can be uploaded using both ArduinoOTA and over the serial port, I recommend this platformio.ini
setup:
Start with your normal config for serial upload:
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200
And now add a new OTA target that extends
the serial config, effectively inheriting the complete build configuration including the lib_deps
:
[env:d1_mini_ota]
extends = env:d1_mini
upload_protocol = espota
upload_port = 192.168.178.166
In upload_port
you need to enter either the IP address or the mDNS name of the board that shall be flashed. The IP address we entered (192.168.178.166
) is just an example.
Also note that depending on the name of your original build target, change
extends = env:d1_mini
to the name of your original target (including env:
)
Complete platformio.ini
example
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200
[env:d1_mini_ota]
extends = env:d1_mini
upload_protocol = espota
upload_port = 10.9.1.106