Flashing OTA of ESP32 failing. [Errno 104] Connection reset by peer

I have something strange going on here. I have many ESP32 (ESP32-WROOM-32D) working but lately updating them with OTA is getting more difficult. They just seem to fail with a timeout. These boards are all working and wireless logging also works 100% of the time, Just a OTA code updated fails. I need to try many times to get a successful update. Updating via a USB cable works every time without issues. Seems to suggest network issues but I have no issues with any ESPHome Wifi devices once the code is flashed. I am also using static IP addresses. But this did not help.
Here are few logs with the failures.

INFO ESPHome 2024.6.6
INFO Reading configuration /config/esphome/esp32-pumps.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esp32-pumps (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.3
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
|-- ArduinoJson @ 6.18.5
|-- Improv @ 1.2.3
RAM:   [==        ]  16.2% (used 52968 bytes from 327680 bytes)
Flash: [========= ]  90.4% (used 1658257 bytes from 1835008 bytes)
========================= [SUCCESS] Took 19.18 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.106
INFO Uploading /data/build/esp32-pumps/.pioenvs/esp32-pumps/firmware.bin (1664032 bytes)
Uploading: [============                                                ] 20% ERROR Error receiving acknowledge chunk OK: [Errno 104] Connection reset by peer

And another one

RAM:   [==        ]  16.2% (used 52968 bytes from 327680 bytes)
Flash: [========= ]  90.4% (used 1658257 bytes from 1835008 bytes)
========================= [SUCCESS] Took 19.29 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.106
INFO Uploading /data/build/esp32-pumps/.pioenvs/esp32-pumps/firmware.bin (1664032 bytes)
Uploading: [=======                                                     ] 12% ERROR Error receiving acknowledge chunk OK: [Errno 104] Connection reset by peer

and another

RAM:   [==        ]  16.2% (used 52968 bytes from 327680 bytes)
Flash: [========= ]  90.4% (used 1658257 bytes from 1835008 bytes)
========================= [SUCCESS] Took 19.16 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.106
INFO Uploading /data/build/esp32-pumps/.pioenvs/esp32-pumps/firmware.bin (1664032 bytes)
Uploading: [====                                                        ] 6% ERROR Error receiving acknowledge chunk OK: [Errno 104] Connection reset by peer

But Wireless logging works fine. Always.

INFO ESPHome 2024.6.6
INFO Reading configuration /config/esphome/esp32-pumps.yaml...
INFO Starting log output from 192.168.1.106 using esphome API
INFO Successfully connected to esp32-pumps @ 192.168.1.106 in 0.073s
INFO Successful handshake with esp32-pumps @ 192.168.1.106 in 0.432s
[20:44:38][I][app:100]: ESPHome version 2024.6.6 compiled on Aug 16 2024, 13:43:18
[20:44:38][I][i2c.arduino:096]: Results from i2c bus scan:
[20:44:38][I][i2c.arduino:102]: Found i2c device at address 0x40

Here is a sample yaml but it does not seem to matter as it effects many boards with different yaml

esphome:
  name: "esp32-pumps"
  friendly_name: "esp32-pumps"

esp32:
  board: esp32dev
  framework:
    type: arduino

api:
  encryption:
    key: qN1ks2Cze123xWx5upTDD6H15IYKYExYwCIPoqHg=


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  manual_ip:
    static_ip: 192.168.1.106
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  ap:
    ssid: "ESP PUMPS HOTSPOT"
    password: "SXYTSAXXSA1234"


logger:
  level: INFO

ota:
  platform: esphome

improv_serial:

web_server:

esp32_improv:
  authorizer: none

i2c:
  sda: GPIO21
  scl: GPIO22

sensor:
  - platform: ina226
    address: 0x40
    shunt_resistance: 0.1 ohm
    id: ina_sensor
    bus_voltage:
      name: "Bilge Pump Voltage"
      id: bilge_pump_voltage
    update_interval: 1s

Had similar issue when WiFi was like a “overloaded”.
OTA failed, as well as devices experienced issues with sending data to HA.
Also connection & handshake timings was big in my case - up to several seconds.
WiFi channel change fixed the issue.

2 Likes

Just wanted to let you know I have the same issue with two ESP_DevKitC_v4’s (ESP32-wroom-32d based).
My problem isn’t just upload (and improves when moving closer to the wifi AP as @Masterzz suggested), but my modules also keep crashing in normal operation. Even with a very simple config (only an “uptime sensor”). I’m not sure if this is just a bad batch of modules or if something broke in a newer release of ESPhome. The weird thing is that one module works just fine (same batch, same ESPHome version etc.)… To be continued.

Might be worth adding the Wi-Fi sensor, I add that and the uptime sensor to all my devices now. Just helps knowing what is going on.

I have solved the problem by reducing the size of the ESPHome code to be flashed and also using a logger of ERROR. I disabled options I did not need like bluetooth etc and the file size to flash went down by 50%.

Hi Robufz,

Do you mind sharing some of those configs you used to remove the unneeded options?

I have posted the code online here…

1 Like

I just had this issue and your post was the first result on Goggle, so here’s my solution:

I have a mesh network with 3 Asus routers. The ESP32 device was connected to the closest router which was perhaps too close (1 meter).
I changed the binding to a router further away and that solved the problem.

Some extra info:
There were also 10 devices connected to the first router and only 2 to the second, so that might have played a role.
It’s a rainy Saturday night so I guess all the neighbours are home using WiFi, which could perhaps contribute to interference.

Same issue for me. I’m using POE though, have my wifi turned off.
compiled but then " OTA Error sending data: [Errno 104] Connection reset by peer"
brought it down and flashed it via usb, working fine now. not sure if it’ll happen again or not.

Edit: just read this on esphome. need to do better at RTFM
Note

The first time this component is enabled for an ESP32, the code partition needs to be resized. Please flash the ESP32 via USB when adding this to your configuration. After that, you can use OTA updates again.