ESP8266 OTA never finishes

Trying OTA on my custom project with ESP07 and external antenna, but it never reached 100% of progress:

Uploading .pio\build\esp07\firmware.bin
20:55:37 [DEBUG]: Options: {'esp_ip': 'esp8266_WeatherStation.local', 'host_ip': '0.0.0.0', 'esp_port': 
8266, 'host_port': 33763, 'auth': 'WeatherStation', 'image': '.pio\\build\\esp07\\firmware.bin', 'spiffs': False, 'debug': True, 'progress': True}
20:55:37 [INFO]: Starting on 0.0.0.0:33763
20:55:37 [INFO]: Upload size: 360720
20:55:37 [INFO]: Sending invitation to: esp8266_WeatherStation.local
Authenticating...OK
20:55:37 [INFO]: Waiting for device...

Uploading: [                                                            ] 0% 
Uploading: [                                                            ] 0% 
Uploading: [                                                            ] 0%
Uploading: [=                                                           ] 1%
Uploading: [=                                                           ] 1%
Uploading: [=                                                           ] 2% 
Uploading: [=                                                           ] 2%
Uploading: [==                                                          ] 2% 
Uploading: [==                                                          ] 3%
Uploading: [==                                                          ] 3%
Uploading: [==                                                          ] 4% 
Uploading: [===                                                         ] 4%
Uploading: [===                                                         ] 4%
Uploading: [===                                                         ] 5%
Uploading: [===                                                         ] 5%
Uploading: [====                                                        ] 6% 
Uploading: [====                                                        ] 6% 
Uploading: [====                                                        ] 6%
Uploading: [====                                                        ] 7% 
Uploading: [=====                                                       ] 7% 
20:55:37 [ERROR]: Error Uploading
*** [upload] Error 1
====================================== [FAILED] Took 5.36 seconds ======================================The terminal process "C:\Users\Jirka\.platformio\penv\Scripts\pio.exe 'run', '--target', 'upload'" terminated with exit code: 1.

When using WeMOS D1 it works without problems.
Could the problem be poor WiFi signal? I am around -70dBm.

That was one suggestion in this issue. Another was some weird interplay between the devices connected to the same access point (although that could be a red herring, and it was the AP itself that was the problem)…

The devs thought they had fixed the somewhat similiar error in the v2.6.2 ESP8266 core… are you running the latest version, or a version later than that (corresponding platformio platform version would be 2.3.1).

1 Like

I have opened PlatformIO and found following:

I am actually not sure if this is ESP8266 core version or not.
How can I check both values you mentioned?

The “platform” version of Espressif 8266 is the PlatformIO numbering / versioning of the PlatformIO integration. platform-espressif8266 version 2.6.2 contains Arduino-ESP8266 core version 2.7.4.

In the platformio.ini of your project, can you replace

platform = espressif8266

by

platform = espressif8266@2.3.1

which will make PIO use Arduino-ESP8266 core version 2.6.2 and see if that changes anything?

1 Like

I have tried, similar result:

Uploading: [============                                                ] 19%
Uploading: [============                                                ] 19%
Uploading: [============                                                ] 20% 
06:09:49 [ERROR]: Error Uploading
*** [upload] Error 1

Stops sometimes by 20%, 1%, 2% …

Here is my platformi.ini:

[env:esp07]
platform = espressif8266@2.3.1
board = esp07
framework = arduino
lib_deps =
    https://github.com/tzapu/WiFiManager
    mathworks/ThingSpeak @ ^1.5.0
    adafruit/Adafruit Unified Sensor @ ^1.1.4
    adafruit/Adafruit BME280 Library @ ^2.1.2
    adafruit/Adafruit ADS1X15 @ ^1.1.1
upload_protocol = espota
upload_port = esp8266_WeatherStation.local
upload_flags =
    --port=8266
    --auth=WeatherStation

Can you try the latest platform (just platform = espressif8266) and no library dependencies with the sketch BasicOTA.ino? Does it have the same problems?

Have you restarted your router?

2 Likes

I have tried BasicOTA.ino in Arduino. It works well. So I guess it eliminated possible HW problems (it is very first version of our HW) and also possible router / WiFi signal issues.

I don’t know how to open INO file in PlatformIO but I will study it if you think it is worth.
What I will try hopefully tomorrow is copy of content of BasicOTA.ino in PlatformIO as CPP file.

Either copy the .ino file directly in the src/ folder of the project, or, preferred, copy the contents of the file into a .cpp file and add #include <Arduino.h> at the top (for general reference, there’s a FAQ about this).

Taken exact content of BasicOTA.ino (changed to .cpp, added #include <arduino.h>).
Changed WiFi credentials.

COM port output:
Start updating sketch
Progress: 0%
Progress: 0%
Progress: 0%
Progress: 1%
Error[4]: End Failed

PlatformIO VSC output:
Uploading: [===== ] 8%
Uploading: [====== ] 9%
Uploading: [====== ] 9%
Uploading: [====== ] 10%
05:30:08 [ERROR]: Error Uploading
*** [upload] Error 1
==================================================================== [FAILED] Took 37.36 seconds ====================================================================The terminal process “C:\Users\Jirka.platformio\penv\Scripts\pio.exe ‘run’, ‘–target’, ‘upload’” terminated with exit code: 1.
platformio.ini:
[env:esp07]
platform = espressif8266
board = esp07
framework = arduino
upload_protocol = espota
upload_port = 200.100.10.226

I just recalled that all my IoT devices are running on isolated network (separate SSID in my home).
But this should be no issue as I have used same SSID for Arduino IDE test and it worked well.

Based on new information from terminal window (COM port) I have found this: OTA Example fails · Issue #3187 · esp8266/Arduino · GitHub. Unfortunately I have not found a way how to properly enable DEBUG_ESP_OTA flag.

From a check of the verbose Arduino IDE compile output, it’s just a define, so you can use build_flags for that…

i.e. add something like build_flags = -DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_OTA to your platformio.ini and see how you go…

1 Like

So this is output on terminal, when trying to run OTA from PlatformIO:


state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 10
cnt

connected with IoT, channel 9
dhcp client start…
ip:200.100.10.226,mask:255.255.255.0,gw:200.100.10.1
OTA server at: esp8266-3e9950.local:8266
Ready
IP address: 200.100.10.226
pm open,type:2 0
sleep disable
Start updating sketch
Progress: 0%
Progress: 0%
Progress: 0%
Progress: 1%
Error[4]: End Failed
ERROR[2]: Flash Erase Failed

According to D1 Mini OTA upload: Flash erase failed · Issue #845 · esphome/issues · GitHub this can also happen when you have a bad flash chip or when the wrong board type (and thush flash memory map) is used in PlatformIO.

Can you show a screenshot of how you configure the Arduino IDE where the upload works?

Can you show the log of a “Verbose Upload” (in the PlatformIO project tasks) when uploading normally via USB/serial? (esptool.py should show information regarding the flash size…)

Especially regarding a report like this is interesting

I have board = esp07, and after found in table Espressif 8266 — PlatformIO latest documentation that it should have 4Mb flash.
But when fleshing by serial port it writes:

Auto-detected Flash size: 1MB

I just changed board to esp01_1m and now OTA works fine!

2 Likes

Output from Arduino IDE (serial programming):

Executable segment sizes:
IROM   : 281860          - code in flash         (default or ICACHE_FLASH_ATTR) 
IRAM   : 27828   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...) 
DATA   : 1276  )         - initialized variables (global, static) in RAM/HEAP 
RODATA : 1216  ) / 81920 - constants             (global, static) in RAM/HEAP 
BSS    : 25472 )         - zeroed variables      (global, static) in RAM/HEAP 
Sketch uses 312180 bytes (32%) of program storage space. Maximum is 958448 bytes.
Global variables use 27964 bytes (34%) of dynamic memory, leaving 53956 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port COM6
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 2c:f4:32:3e:99:50
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 1MB
Compressed 316336 bytes to 229032...
Wrote 316336 bytes (229032 compressed) at 0x00000000 in 20.4 seconds (effective 124.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Detected 1MB of FLASH is also the same value as my friend who did HW told me.

Here Arduino IDE configuration:
ArduinoConfig2

And COM port output when flashing from Arduino IDE via OTA:

Start updating sketch
Progress: 0%
Progress: 0%
...
Progress: 99%
Progress: 100%
End

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
@cp:0
ld
Booting
Ready
IP address: 200.100.10.226

After flashing via Arduino IDE (serial followed by OTA)
I have tried to flash with PlatformIO via OTA:

platformio.ini:

[env:esp01_1m]
platform = espressif8266
board = esp01_1m          ; ESP07 with 1MB FLASH
framework = arduino
upload_protocol = espota
upload_port = 200.100.10.226
build_flags = 
    -DDEBUG_ESP_PORT=Serial 
    -DDEBUG_ESP_OTA

Terminal output:

> Executing task in folder BasicOTA: C:\Users\Jirka\.platformio\penv\Scripts\pio.exe run --target upload <

Processing esp01_1m (platform: espressif8266; board: esp01_1m; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp01_1m.html
PLATFORM: Espressif 8266 (2.6.2) > Espressif Generic ESP8266 ESP-01 1M
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
PACKAGES:
 - framework-arduinoespressif8266 3.20704.0 (2.7.4)
 - tool-esptool 1.413.0 (4.13)
 - tool-esptoolpy 1.20800.0 (2.8.0)
 - tool-mklittlefs 1.203.200522 (2.3) 
 - tool-mkspiffs 1.200.0 (2.0)
 - toolchain-xtensa 2.40802.200502 (4.8.2)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ArduinoOTA> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ESP8266mDNS> 1.2
|   |   |-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
Building in release mode
Retrieving maximum program size .pio\build\esp01_1m\firmware.elf
Checking size .pio\build\esp01_1m\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  34.4% (used 28188 bytes from 81920 bytes)
Flash: [====      ]  41.3% (used 314568 bytes from 761840 bytes)
Configuring upload protocol...
AVAILABLE: espota, esptool
CURRENT: upload_protocol = espota
Uploading .pio\build\esp01_1m\firmware.bin
19:12:14 [DEBUG]: Options: {'esp_ip': '200.100.10.226', 'host_ip': '0.0.0.0', 'esp_port': 8266, 'host_port': 28918, 'auth': '', 'image': '.pio\\build\\esp01_1m\\firmware.bin', 'spiffs': False, 'debug': True, 'progress': True}
19:12:14 [INFO]: Starting on 0.0.0.0:28918
19:12:14 [INFO]: Upload size: 318720
19:12:14 [INFO]: Sending invitation to: 200.100.10.226
19:12:14 [INFO]: Waiting for device...

Uploading: [                                                            ] 0%
Uploading: [                                                            ] 0%
Uploading: [=                                                           ] 0%
Uploading: [=                                                           ] 1% 
...
Uploading: [============================================================] 99%
Uploading: [============================================================] 100% Done...


19:12:21 [INFO]: Waiting for result...
19:12:22 [INFO]: Result: OK
=================================================================== [SUCCESS] Took 12.27 seconds ===================================================================

Terminal will be reused by tasks, press any key to close it.

Many thanks. It seems that this was my problem - wrong board configuration.
I am very thankful all contributors above. How can I thank you?

2 Likes