Connecting to Wifi fails multiple times, every time, before finally working

Hi,

ESPs programmed with ESPHome always fail to connect to wifi for ~4 times before succeeding. This increases the time it takes drastically, making battery powered devices near impossible.

I’ve tried different ESPs (d1 mini, 32c3, 32c6) to make sure it’s not a hardware issue. Also tried to program the ESPs directly and getting no problems there, so it’s also no issue of my WiFi.

The device is close to the router and IP is static.

Here is the relevant part of the log:

[22:31:00][I][logger:171]: Log initialized
[22:31:00][C][safe_mode:079]: There have been 1 suspected unsuccessful boot attempts
[22:31:00][D][esp32.preferences:114]: Saving 1 preferences to flash...
[22:31:00][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[22:31:00][I][app:029]: Running through setup()...
[22:31:00][I][i2c.arduino:218]: Performing I2C bus recovery
[22:31:01][C][aht10:050]: Setting up AHT10
[22:31:01][C][wifi:048]: Setting up WiFi...
[22:31:01][C][wifi:061]: Starting WiFi...
[22:31:01][C][wifi:062]:   Local MAC: 48:12:B7:56:70:E8
[22:31:01][D][wifi:482]: Starting scan...
[22:31:01][W][component:157]: Component wifi set Warning flag: scanning for networks
[22:31:01][D][sensor:094]: 'AHT10 Temperature': Sending state 25.01202 °C with 2 decimals of accuracy
[22:31:01][D][sensor:094]: 'AHT10 Humidity': Sending state 35.90517 % with 2 decimals of accuracy
[22:31:02][D][wifi:497]: Found networks:
[22:31:02][I][wifi:541]: - 'MyRouter' [redacted]▂▄▆█
[22:31:02][D][wifi:542]:     Channel: 6
[22:31:02][D][wifi:543]:     RSSI: -54 dB
[22:31:02][I][wifi:541]: - 'MyRouter' [redacted]▂▄�[D][wifi:543]:     RSSI: -81 dB
[22:31:02][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:02][W][wifi_esp32:545][arduino_events]: Event: Disconnected ssid='MyRouter' bssid=[redacted] reason='Authentication Failed'
[22:31:02][W][wifi:674]: WiFi Unknown connection status 0
[22:31:02][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:02][W][wifi_esp32:545][arduino_events]: Event: Disconnected ssid='MyRouter' bssid=[redacted] reason='Authentication Failed'
[22:31:02][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[22:31:03][W][wifi_esp32:545][arduino_events]: Event: Disconnected ssid='MyRouter' bssid=[redacted] reason='Auth Expired'
[22:31:07][D][wifi:482]: Starting scan...
[22:31:09][D][wifi:497]: Found networks:
[22:31:09][I][wifi:541]: - 'MyRouter' [redacted]▂▄▆█
[22:31:09][D][wifi:542]:     Channel: 6
[22:31:09][D][wifi:543]:     RSSI: -81 dB
[22:31:09][I][wifi:541]: - 'MyRouter' [redacted]▂▄▆█
[22:31:09][D][wifi:542]:     Channel: 6
[22:31:09][D][wifi:543]:     RSSI: -53 dB
[22:31:09][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:09][W][wifi:653]: Error while connecting to network.
[22:31:09][D][wifi:697]: Retrying with hidden networks...
[22:31:09][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:09][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[22:31:10][W][wifi_esp32:545][arduino_events]: Event: Disconnected ssid='MyRouter' bssid=[redacted] reason='Auth Expired'
[22:31:14][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:14][W][wifi:653]: Error while connecting to network.
[22:31:14][D][wifi:697]: Retrying with hidden networks...
[22:31:14][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:14][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[22:31:14][D][wifi:697]: Retrying with hidden networks...
[22:31:15][W][wifi_esp32:545][arduino_events]: Event: Disconnected ssid='MyRouter' bssid=[redacted] reason='Authentication Failed'
[22:31:19][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:19][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[22:31:19][W][wifi:690]: Restarting WiFi adapter...
[22:31:19][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:20][W][wifi_esp32:545][arduino_events]: Event: Disconnected ssid='MyRouter' bssid=[redacted] reason='Auth Expired'
[22:31:20][W][wifi:653]: Error while connecting to network.
[22:31:20][D][wifi:697]: Retrying with hidden networks...
[22:31:25][I][wifi:313]: WiFi Connecting to 'MyRouter'...
[22:31:29][I][wifi:617]: WiFi Connected!
[22:31:29][C][wifi:428]:   Local MAC: 48:12:B7:56:70:E8
[22:31:29][C][wifi:433]:   SSID: [redacted]
[22:31:29][C][wifi:436]:   IP Address: 192.168.188.63
[22:31:29][C][wifi:440]:   BSSID: [redacted]
[22:31:29][C][wifi:441]:   Hostname: 'aht10'
[22:31:29][C][wifi:443]:   Signal strength: -58 dB ▂▄▆█
[22:31:29][C][wifi:447]:   Channel: 6
[22:31:29][C][wifi:448]:   Subnet: 255.255.255.0
[22:31:29][C][wifi:449]:   Gateway: 192.168.188.1
[22:31:29][C][wifi:450]:   DNS1: 0.0.0.0
[22:31:29][C][wifi:451]:   DNS2: 0.0.0.0
[22:31:29][C][api:026]: Setting up Home Assistant API server...
[22:31:29][I][app:062]: setup() finished successfully!

You are probably running a SSD on your access point that support both 2.4Ghz and 5Ghz.
Your access point is trying to push the 2.4Ghz connected devices over to 5Ghz by kicking them off and denying access to the 2.4Ghz network.
The access point have no way to see that a device is only 2.4Ghz, so this is it’s way to test if a device can run 5Ghz.

Access points can usually be configured to have different SSID for 2.4Ghz and 5Ghz and some can also have multiple SSIDs, where one or more then can be set to only run a single frequency band.

They can and they do. If a device is only connecting via 2.4GHz and not on 5GHz a proper AP (software) shouldn’t attempt band steering at all :handshake:

Band steering in a nutshell: When an access point gets two requests (on 2.4+5GHz) it will just reply on the 5GHz to force (steer to) this band ::tada:

If an AP “tries” band steering if a device only connects via 2.4GHz then this is nothing but bug :bug:

To illustrate (a picture says more then thousand words):

Picture2_bbb6ff26-4619-446a-a859-7ffdac99ec20_600x600

@WallyR did you participate in groundhog day the last years? :thinking:

While you are both right, and AP can be configured this way, I don’t see the need to do so. As I’ve said, this problem is exclusive to ESPhome, when programmed directly the ESPs connects in ~411ms (average of 30 runs).

If an AP “tries” band steering if a device only connects via 2.4GHz then this is nothing but bug

Personally, I’d call it a bug. But even if we pretend it is a feature, then it is still extremely unoptimized and needs to be changed.

1 Like

What make and model is your AP? You might be capable of upgrading it to openwrt if it really is a software limitation/bug :signal_strength:

Also your yaml part related to WiFi might be nice for the full picture. :framed_picture:

this is what UI says about band steering
https://community.ui.com/questions/Band-steering-how-does-it-work/7d33375b-57a5-48b2-b1f4-214ee7bd2b60

it seems they didn’t get your memo about how it should work.

What is Band Steering? Improve your Wi-Fi | devolo seems to have a similar strategy

You might find it possible to convince them to change their mind about it. Many people just choose to turn off band steering and/or us different SSIDs for the different bands. It is going to depend on your environment and router/APs what works best.

Thanks for the suggestion, but I’m not going to flash openwrt on my hardware to fix ESPHomes bad wifi implementation. I’ll just go back to programming the ESPs independently and use MQTT to get the data into HA.

Maybe your hardware have the option exposed already.
OpenWRT should not be necessary.

Using MQTT is the recommended way for battery powered devices, based on my limited knowledge.

If what you are using is working for you that is great. Every tool/component has things that work well and things that are less than optimal for any given project.

I am not convinced esphome is the source of the issue you see, since I am pretty sure the Wi-Fi stack comes from either the Arduino platform (if you are using that) or from Espressif (they are responsible for the underlying hardware/firmware in both cases). It is possible you are using a different framework version in your non-esphome case. I do remember a time when there was a new framework for the esp8266 and Wi-Fi was horribly unreliable. It took people working together months to figure out what was going on and get it fixed.

Clearly you are seeing something, but have provided no actionable information to potentially figure out what might be causing. It might be a bug as you suspect and it might even be in esphome, but it is unlikely to ever be fixed if you are the only person seeing it and you don’t provide any real information or interest in helping debug the issue.

I came to esphome because it does an excellent job with OTA updates and I :two_hearts: that about it. Everything else has been a steep learning curve and I have decades of professional experience with C/C++, Python, hardware, firmware, software, networking, engineering. Easy things (the “hello world” of hardware) are easy, but some (what seem like should be) slightly harder things seem nearly impossible. But, some hard things are also easy (OTA being the one I care about most).

I hope you find something that works for your needs.

Nope. No idea what that is, unless it is some obscure American tradition that have been made into a comedy movie. :slight_smile: