Upload_port is a device path, but PIO tries OTA upload

PlatformIO, version 4.0.0a3
MacOS 10.14.3

In my platformio.ini file, I have the serial port for my device defined as upload_port = /dev/cu.usbserial-14413440, which matches what I see in ls /dev/cu.* output and matches what I see in pio device list:

/dev/cu.usbserial-14413430
--------------------------
Hardware ID: USB VID:PID=1A86:7523 LOCATION=20-4.1.3.4.3
Description: USB2.0-Serial

However, when I try to upload my project (an ESP8266/Arduino project), PIO tries to upload via OTA. This is a new problem. Just 3 days ago, uploading by serial worked fine. I did not make changes to the platformio.ini file in that time.

Iā€™m not sure what the issue is, but is there a way to force PIO to perform serial upload? Iā€™ve also tried with the tty version of the port (/dev/tty.usbserial-14413430), but it has the same issue.

What command are you using for uploading? Via the CLI or an IDE? What is the verbose output of that procedure?

Happens in both IDE (VSCode) and CLI, using command pio run --target upload.

The non-verbose output is:

Configuring upload protocol...
Looking for upload port...
Use manually specified: /dev/cu.usbserial-14413430
Uploading .pioenvs/nodemcu/firmware.bin
06:09:11 [DEBUG]: Options: {'timeout': 10, 'esp_ip': '/dev/cu.usbserial-14413430', 'host_port': 33677, 'image': '.pioenvs/nodemcu/firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 8266, 'spiffs': False, 'debug': True, 'progress': True}
06:09:11 [INFO]: Starting on 0.0.0.0:33677
06:09:11 [INFO]: Upload size: 273568
Sending invitation to /dev/cu.usbserial-14413430 ....failed
06:09:50 [ERROR]: Host /dev/cu.usbserial-14413430 Not Found

I just tried to enable verbose, and now it correctly finds the serial port and uploads properly. I made no changes to the code or settings, the host computer was not even restarted, the hardware (NodeMCU) was not uplugged. Odd.

Can you show your full platformio.ini?

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
env_default = nodemcu

[common_env_data]
framework = arduino
monitor_speed = 115200
lib_deps = 
  FastLED

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = ${common_env_data.framework}
upload_port = /dev/cu.usbserial-14413440
monitor_port = /dev/cu.usbserial-14413440
monitor_speed = ${common_env_data.monitor_speed}
lib_deps = ${common_env_data.lib_deps}

[env:nodemcu]
platform = espressif8266
board = nodemcu
framework = ${common_env_data.framework}
upload_port = /dev/cu.usbserial-14413430
monitor_port = /dev/cu.usbserial-14413430
monitor_speed = ${common_env_data.monitor_speed}
lib_deps = ${common_env_data.lib_deps}

This happens on Windows platforms too and is a serious issue.

The new 2.0.x releases appear to break the upload_port setting in platformio.ini: it looks like it now interprets the upload_port as an IP address instead of a COM port. This is very easy to reproduce: for example, using the auto-generated platformio.ini configuration and adding just the upload port specification:

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_port=COM5

Attempts to upload to target now result in:

Uploading .pioenvs\esp12e\firmware.bin
12:08:00 [DEBUG]: Options: {'timeout': 10, 'esp_ip': 'COM5', 'host_port': 46511, 'image': '.pioenvs\\esp12e\\firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 8266, 'spiffs': False, 'debug': True, 'progress': True}
12:08:00 [INFO]: Starting on 0.0.0.0:46511
12:08:00 [INFO]: Upload size: 262160
Sending invitation to COM5 ..........
12:09:41 [ERROR]: No response from the ESP

Any ideas? I didnā€™t see anything helpful in the release notes. How do I tell it to use a specific serial port for upload? (Note: if no upload port is specified, it auto-detects the first serial port, but thatā€™s not the one I need to use).

I cannot reproduce this on my Windows PC.

platformio.ini

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

Upload via pio run -t upload -v

[..]
<lambda>(["upload"], [".pioenvs\nodemcuv2\firmware.bin"])
MethodWrapper(["upload"], [".pioenvs\nodemcuv2\firmware.bin"])
Use manually specified: COM7
esptool -vv -cd nodemcu -cb 115200 -cp "COM7" -cf .pioenvs\nodemcuv2\firmware.bin
esptool v0.4.13 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
setting board to nodemcu
setting baudrate from 115200 to 115200
setting port from COM1 to COM7
espcomm_upload_file
writing flash
................................................................................ [ 31% ]
................................................................................ [ 62% ]
................................................................................ [ 93% ]
.................                                                                [ 100% ]
[...]
======================================================================================================= [SUCCESS] Took 35.39 seconds =======================================================================================================

Can you try via the terminal?

Same problem when run from the terminalā€¦it is 100% reproducible. If I comment out the upload_port (and the target is the first serial port), it uploads over serial. However if I un-comment that line, it attempts an OTA upload.

([ā€œuploadā€], [".pioenvs\esp12e\firmware.bin"])
MethodWrapper([ā€œuploadā€], [".pioenvs\esp12e\firmware.bin"])
Use manually specified: COM5
ā€œc:\users\david.platformio\penv\scripts\python.exeā€ ā€œC:\Users\david.platformio\packages\tool-espotapy\espota.pyā€ --debug --progress -i COM5 -f .pioenvs\esp12e\firmware.bin
12:51:51 [DEBUG]: Options: {ā€˜timeoutā€™: 10, ā€˜esp_ipā€™: ā€˜COM5ā€™, ā€˜host_portā€™: 41851, ā€˜imageā€™: ā€˜.pioenvs\esp12e\firmware.binā€™, ā€˜host_ipā€™: ā€˜0.0.0.0ā€™, ā€˜authā€™: ā€˜ā€™, ā€˜esp_portā€™: 8266, ā€˜spiffsā€™: False, ā€˜debugā€™: True, ā€˜progressā€™: True}
12:51:51 [INFO]: Starting on 0.0.0.0:41851
12:51:51 [INFO]: Upload size: 509408

Time to compare versions then. Can you please upgrade the core to the latest dev version using pio upgrade --dev in the terminal? Also whatā€™s the platform-esp8266 version when you type in pio platforms show espressif8266? Itā€™s Version: 2.0.1 for me.

Itā€™s 2.0.1 for me too. Note: Iā€™ve tried falling back to 2.0.x and it has the same issue.

PS C:\Users\david\Documents\PlatformIO\Projects\Gateway2> pio platforms show espressif8266
espressif8266 ~ Espressif 8266
==============================
Espressif Systems is a privately held fabless semiconductor company. They provide wireless communications and Wi-Fi chips which are widely used in mobile devices and the Internet of Things applications.

Version: 2.0.1
Home: http://platformio.org/platforms/espressif8266
Repository: https://github.com/platformio/platform-espressif8266.git
Vendor: https://espressif.com/
License: Apache-2.0
Frameworks: arduino, esp8266-nonos-sdk, esp8266-rtos-sdk, simba

Packages
--------

Package framework-esp8266-rtos-sdk
----------------------------------
Type: framework
Requirements: >=1.5.0-beta
Installed: No (optional)

Package toolchain-xtensa
------------------------
Type: toolchain
Requirements: ~1.40802.0
Installed: Yes
Version: 1.40802.0
Original version: 4.8.2
Description: xtensa-gcc

Package framework-simba
-----------------------
Type: framework
Requirements: >=7.0.0
Installed: No (optional)

Package tool-esptool
--------------------
Type: uploader
Requirements: <2
Installed: Yes
Version: 1.413.0
Original version: 4.13
Description: esptool-ck

Package tool-mkspiffs
---------------------
Type: uploader
Requirements: ~1.200.0
Installed: Yes
Version: 1.200.0
Original version: 2.0
Description: Tool to build and unpack SPIFFS images

Package tool-espotapy
---------------------
Type: uploader
Requirements: ~1.1.0
Installed: Yes
Version: 1.1.3
Original version: None
Description: This script will push an OTA update to the ESP

Package framework-arduinoespressif8266
--------------------------------------
Type: framework
Requirements: ~2.20500.0
Installed: Yes
Version: 2.20500.190223
Original version: 2.5.0
Description: Arduino Wiring-based Framework (ESP8266 Core)

Package sdk-esp8266
-------------------
Requirements: ~1.10502.0
Installed: Yes
Version: 1.10502.0
Original version: 1.5.2
Description: ESP8266 SDK

Package framework-esp8266-nonos-sdk
-----------------------------------
Type: framework
Requirements: >=2.1.0
Installed: No (optional)

Boards
------
ID                    MCU            Frequency  Flash   RAM    Name
----------------------------------------------------------------------------------------------------------------------------------------------------------
nodemcuv2             ESP8266        80MHz     4MB     80KB   NodeMCU 1.0 (ESP-12E Module)
wifinfo               ESP8266        80MHz     1MB     80KB   WifInfo
esp01_1m              ESP8266        80MHz     1MB     80KB   Espressif Generic ESP8266 ESP-01 1M
d1_mini               ESP8266        80MHz     4MB     80KB   WeMos D1 R2 and mini
espduino              ESP8266        80MHz     4MB     80KB   ESPDuino (ESP-13 Module)
esp12e                ESP8266        80MHz     4MB     80KB   Espressif ESP8266 ESP-12E
heltec_wifi_kit_8     ESP8266        80MHz     4MB     80KB   Heltec Wifi kit 8
wifiduino             ESP8266        80MHz     4MB     80KB   WiFiduino
huzzah                ESP8266        80MHz     4MB     80KB   Adafruit HUZZAH ESP8266
phoenix_v1            ESP8266        80MHz     4MB     80KB   Phoenix 1.0
phoenix_v2            ESP8266        80MHz     4MB     80KB   Phoenix 2.0
d1                    ESP8266        80MHz     4MB     80KB   WEMOS D1 R1 (Retired)
esp01                 ESP8266        80MHz     512KB   80KB   Espressif Generic ESP8266 ESP-01 512k
esp07                 ESP8266        80MHz     4MB     80KB   Espressif Generic ESP8266 ESP-07
thing                 ESP8266        80MHz     512KB   80KB   SparkFun ESP8266 Thing
esp_wroom_02          ESP8266        80MHz     2MB     80KB   ESP-WROOM-02
sparkfunBlynk         ESP8266        80MHz     4MB     80KB   SparkFun Blynk Board
oak                   ESP8266        80MHz     4MB     80KB   DigiStump Oak
wifi_slot             ESP8266        80MHz     4MB     80KB   WiFi Slot
nodemcu               ESP8266        80MHz     4MB     80KB   NodeMCU 0.9 (ESP-12 Module)
d1_mini_lite          ESP8266        80MHz     1MB     80KB   WeMos D1 mini Lite
espresso_lite_v1      ESP8266        80MHz     4MB     80KB   ESPresso Lite 1.0
espresso_lite_v2      ESP8266        80MHz     4MB     80KB   ESPresso Lite 2.0
d1_mini_pro           ESP8266        80MHz     16MB    80KB   WeMos D1 mini Pro
esp8285               ESP8266        80MHz     1MB     80KB   Generic ESP8285 Module
espino                ESP8266        80MHz     4MB     80KB   ESPino
inventone             ESP8266        80MHz     4MB     80KB   Invent One
espinotee             ESP8266        80MHz     4MB     80KB   ThaiEasyElec ESPino
espectro              ESP8266        80MHz     4MB     80KB   ESPectro Core
thingdev              ESP8266        80MHz     512KB   80KB   SparkFun ESP8266 Thing Dev
modwifi               ESP8266        80MHz     2MB     80KB   Olimex MOD-WIFI-ESP8266(-DEV)
wio_link              ESP8266        80MHz     4MB     80KB   Wio Link
gen4iod               ESP8266        80MHz     512KB   80KB   4D Systems gen4 IoD Range
xinabox_cw01          ESP8266        80MHz     4MB     80KB   XinaBox CW01
esp210                ESP8266        80MHz     4MB     80KB   SweetPea ESP-210
wio_node              ESP8266        80MHz     4MB     80KB   Wio Node

There is a suspicious commit Branch for espota if port resolved (#97) Ā· platformio/platform-espressif8266@54cd0fb Ā· GitHub which might have caused this. The previous logic only allowed IP address strings to be OTA upload ports. The new logic checks if it can resolve the name. Can you try to write upload_protocol = esptool in the platformio.ini?

You might also try to platform = espressif8266@1.8.0 where this commit wasnā€™t yet present.

Iā€™ll try that. I should mention in case itā€™s related that Iā€™m getting a task error when I launch the upload:
Error: The PlatformIO task detection didnā€™t contribute a task for the following configuration:
{
ā€œtypeā€: ā€œPlatformIOā€,
ā€œtaskā€: ā€œUpdate installed platforms, packages and librariesā€,
ā€œproblemMatcherā€: [
ā€œ$platformioā€
]
}
The task will be ignored.

The commit you mentioned certainly looks like the problem.

1.8.0 worked fine (although I had to change some other code that is incompatible between 1.8.0 and 2.0.x (I access the main task to get the stack size and cont.h has changed).

After pio upgrade --dev, I canā€™t seem to access the platforms anymore; how do I roll back to release version?

What exact error message did you get? Do you have two PIO cores installed maybe? (VScode-internal and one externally installed via pip?)

When I try to access the platforms from PIO home, I just get the loading circle indefinitely. How do I get off the development branch?

(and no,Iā€™ve installed nothing via pip)

Well thereā€™s no integrated way to get back :S. Restart the IDE maybe? Iā€™d just re-install the plugin from scratch if it doesnā€™t work.

Never mind, restarting VSCode cleared the problem with accessing the Platforms. Iā€™ll try again with 1.8.0

platform = espressif8266@1.8.0 works as expected (properly with upload_port=COM5)
It fails with platform = espressif8266@2.0.0 or 2.0.1

ā€¦and I think you nailed the problem commit. Is there any easy way for me to patch that locally until it gets resolved?

BTW, thanks so much for all of your help!

1 Like

I think too. Now the real next question is why the python code socket.gethostbyname("COM5") doesnā€™t throw a socket.error exception for you, preventing an OTA upload. Can you ping COM5 or nslookup COM5 on the command line just for fun? Part of the problem is also that this is somehow a resolvable name for your PC.

When using the newer platform version youā€™d have to manually fix the platform-espressif8266/builder/main.py unfortunately :confused:.