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:
platformio_env_d1_mini.ini
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
monitor_speed = 115200And now add a new OTA target that extends the serial config, effectively inheriting the complete build configuration including the lib_deps:
platformio_env_d1_mini_ota.ini
[env:d1_mini_ota]
extends = env:d1_mini
upload_protocol = espota
upload_port = 192.168.178.166In 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
platformio_env_d1_mini.ini
extends = env:d1_minito the name of your original target (including env:)
Complete platformio.ini example
platformio_complete_example.ini
[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.106Check out similar posts by category:
Electronics, ESP8266/ESP32, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow