Nes ESP32 fails to connect for the first time

I’m trying to configure a new ESP32. Clicked the “New device” button in ESPHome, got the message that I’m not using HTTPS, clicked “Continue”, provided a name,selected the type (ESP32-S2) and got the encryption key. Then I selected “Plug into this computer”, downloaded the .bin project and opened ESPHome Web. I connected the USB cable from the ESP32 to the PC, clicked connect, selected the COM1 that showed up, and the message was “ESP Device connected”. I selected “Install” and chose the .BIN file created above.

After waiting for about a minute, I got the message “Failed to initialize. Try resetting your device or holding the BOOT button while selecting your serial port until it starts preparing the installation.”
I tried to repeat the connection holding the boot, reset the ESP32 (power off/on), reset the computer, but always got the same result.

My system is HA 10.2, ESPHome 2023.5.5 running in a VM under a Windows host. The ESPHome Web was running on the Windows machine that hosts the HA. The ESP32 is an Ai Thinker ESP-12k (ESP32 S2).

Any ideas on this issue?

I don’t use ESP32 boards, but I have flashed many ESP8266 boards.

Try making a binary file with “Manual Download, Legacy format”. This will assure that the yaml file compiles OK.

If this works, do it again using “Plug into this computer”. Make sure the ESP is in flash mode. Normally by pressing the flash button as you power up the ESP. You can release the flash button now. Note the com port as you plug in the ESP to the USB port on your PC.

Select the com port of the ESP then the device should be flashed after a minute or so.

I’ve never used ESPHome Web.

Thanks for the suggestion, stevemann.
How should I get to this “Manual Download, Legacy format”? When I try to add a device in ESPHome I get only these options:
image

Also, you mention that you’ve never used ESPHome Web. Me neither, my previous boards were added directly from ESPHome, but it directed me to the Web version as the only resource, apparently. I’m open to alternatives, if compatible with my setup.

You get this when you click on “Install”.

Here’s my steps for creating a new device. It works for me but others will have different methods. Basically, I start with a blank sheet.

Create the device YAML file in the ESPHome UI, “+ New Device”.
Give the device a name then click on “NEXT”.
new device next

Click “Skip this step”.
installation skip this step

Select your Device Type- click anything. It doesn’t matter because we will be erasing everything.
select your device type

When you see"Configuration Created", click on “SKIP”. (Ignore the encryption key).

Now, in the ESPHome UI, find your device and click on “EDIT”.

Erase everything.
Now I paste a boilerplate. A copy of another similar device.

substitutions:
  device_name: esp32-s2
  friendly_name: esp32_s2

esphome:
  name: ${device_name}

esp32:
  board: esp32-s2-saola-1
  framework:
    type: arduino

logger:

api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
sensor:
  - platform: wifi_signal
    name: ${friendly_name} WiFi Level
    update_interval: 300s  

web_server:
  port: 80 

Change the device_name and friendly_name. The device_name may not have an inderscore, and friendly name may not have a dash. I don’t know why- ask the developers. The device_name is used only in the next section. The friendly_name is used to name entities in the rest of the yaml file.
Next, click on “INSTALL”

Here, I always select “Manual download”, “Legacy format”. This verifies that my code compiles OK. (Errors are displayed in red).

After the compile finishes, click on “STOP”.

========================= [SUCCESS] Took 98.70 seconds =========================
INFO Successfully compiled program.

From here you can either use ESPHome Flasher to upload the binary, or click on “INSTALL” again and this time select “Plug into this computer”.

Select the COM port that the UART is plugged into- be sure to put the ESP into the flash mode when you plug in the UART.

Click “Connect”.

If all goes well, in about a minute you will see “Configuration installed!”.
Click on “CLOSE”. (Why does that icon look kike a taco?)
Configuration installed close

Click on the “X” at the top left of the edit page.
On the ESPHome UI page, find your device and click on “VISIT”.

Visit opens the device’s web server that the “web_server:” line gives you. In the boilerplate I included one sensor for the WiFi signal level and you should see this sensor on the web page.

You have created and installed a new device. From here you can edit it and add sensors, switches, etc, and when you click on “INSTALL”, you can select “Wireless”.

Like I said above, this is how I make my new devices. You may find methods that work for you.

Thank you for the very detailed tutorial!
I did follow step by step, but when trying to flash the board I got the same error message as before.

The compilation was sucsessful, i clicked on “INSTALL” again, then my only option was to use ESPHome Web.
image

In that page, I connected my board
image
image
Here I was pressing the “boot” button on the board while clicking connect.
image

Then clicked “INSTALL”
image
Uploaded the file, clicked INSTALL again, and afer a while, I got the same error message mentioned at my first message “Failed to initialize. Try resetting your device or holding the BOOT button while selecting your serial port until it starts preparing the installation.”
For some reason it can’t flash the board. It does not seem to be related to the YAML compilation.

I considered trying ESPHome Flasher, as you suggested. Downloaded from github, but couldn’t make it work. The readme says
“## Installation
It doesn’t have to be installed, just double-click it and it’ll start.”

The question is: double click what? There is no executable in the downloaded folder…

Well… Stuck again.

What computer is this on?

As I said, I don’t have an ESP32 board. (Dozens of ESP8288 boards, however), but I recall that the button is labeled “Flash”. But to be certain you can simply ground GPIO0 when you power up.

The host hardware is an i3 9100F, 8GB RAM, running Windows 10 Pro, VirtualBox and HA.

Tried that, powered up the ESP with GPIO0 connected to GND, and removed the wire after a few seconds. Same results…

But your question made me think that maybe the problem could be related to the computer.
I tried to connect to two other machines, had to install a driver, but finally one of them could connect and upload the BIN file. It seems to be working fine now!
This got me a little disappointed with this new way to startup new ESPs. Three years ago I had no difficulty at all to initialize my ESPs. I still have to find a way that is not so hardware-selective.

Thanks for the help, stevemann!

Hi,
I have the same issue. I tried with 2 machines :

  • PC Windows 10 (ryzen 7)
  • HP Gen8 windows server 2019
    Could you please let me know what’s the driver you put to solve this problem ?
    Here is the view on the Ryzen: