Platformio+VsCode OTA Upload defaults to "COMx" instead of IP

I’m trying to make an OTA on my ESP32. The cpp is OK and manually triggering the update works fine but when I click on VS Code on the “Upload” button, it defaults to “COMx” instead of the given IP.

Manual call:
python C:\Users\<user>\.platformio\packages\framework-arduinoespressif32\tools\espota.py --ip 192.168.178.51 --port 3232 --timeout 60 --file "firmware.bin" --debug

this works perfectly, I get the given firmware on my ESP.

Call via VS Code

What I want now is to trigger the upload using PlatformIOs IDE buttons on VS code.
image

My plaftormio.ini file:

[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
upload_port = 192.168.178.51
monitor_speed = 115200
; OTA
upload_protocol = espota
upload_flags =
    --port=3232
board_build.partitions = min_spiffs.csv
build_unflags = -Os

I build the project → all OK

When I click on UPLOAD, on the terminal I see:

Executing task: C:\Users\<user>\.platformio\penv\Scripts\platformio.exe run --target upload --upload-port COM5

Then it fails with the following information:

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   8.2% (used 43848 bytes from 532480 bytes)
Flash: [====      ]  42.8% (used 841746 bytes from 1966080 bytes)
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = espota
Uploading .pio\build\az-delivery-devkit-v4\firmware.bin
08:53:22 [DEBUG]: Options: {'esp_ip': 'COM5', 'host_ip': '0.0.0.0', 'esp_port': 3232, 'host_port': 30698, 'auth': '', 'image': '.pio\\build\\az-delivery-devkit-v4\\firmware.bin', 'spiffs': False, 'debug': True, 'progress': True, 'timeout': 10}
08:53:22 [INFO]: Starting on 0.0.0.0:30698
08:53:22 [INFO]: Upload size: 841856
Sending invitation to COM5 failed
08:53:24 [ERROR]: Host COM5 Not Found
*** [upload] Error 1

Why is the Upload-button not reading my IP and kept fixed to my COM5? I already disconnected COM5 but it is still defaulting to it.

I’ve removed and reinstalled the platformio IDE on VS Code, but the problem persists.

Any ideas how to fix this?

Do you have multiple projects in your VS Code workspace?

If so, make sure you have selected the correct project and environment in the project environment switcher

Please remove this:

Why this:

?

Is this your complete platformio.ini or are there more lines than you have shown?

I only have 1 project on my workspace.

Under Miscellaneous I only have “Rebuild Intellisense Index” and “Upgrade PlatformIO Core”.
image

At the switcher I have only Default and ebv:az-delivery-devkit-v4
I’ve tried both options, with the same result:

Sending invitation to COM5 failed
11:49:04 [ERROR]: Host COM5 Not Found

The build_unflags = -Os is to optimize for flash size

My complete platformio.ini is:

[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
upload_port = 192.168.178.51
monitor_speed = 115200
; OTA
upload_protocol = espota
upload_flags =
    --port=3232
board_build.partitions = min_spiffs.csv
build_unflags = -Os
lib_compat_mode = strict
lib_deps =
    ArduinoOTA
    knolleary/PubSubClient@^2.8
    bblanchon/ArduinoJson@^7.2.0
    paulstoffregen/OneWire@^2.3.8
    milesburton/DallasTemperature@^3.11.0
    thomasfredericks/Bounce2@^2.72

Note: I removed the lines starting with ;

I did not read this part, sorry.

I’ve commented the part on my platformio.ini file and tried again, with the same result as above.

Beside the Project Environment Switcher, you have to set the upload/monitor/test port to AUTO:

image

Perfect! Thanks a lot.

12:56:43 [INFO]: Waiting for result...
12:56:44 [INFO]: Result: OK
12:56:44 [INFO]: Success