Esp cannot connect to WiFi without computer connection

Update:
Awwww, sh*t! It was all because I had used PIN12. I guess reading error messages would have helped. I’ll mark this as solved…

@@@@@@@@@@@@@

Hi all,

Ugh, I have an odd issue and no clue how this can happen. Also have to take care of the children and little time for debugging and analysis :dizzy_face:

So, I have this esp32, nothing fancy, with a motion sensor, again nothing fancy here. It’s been working flawlessly for months already and the automation to turn on the light worked perfectly as well.

Now yesterday, I unplugged the esp for a few minutes, then plugged it in again, and it stopped connecting to the WiFi. I tried plugging the esp into my computer, connected with esphome and read the logs locally. It then actually connected to the WiFi after 2-3 attempts (wrong password message?!), then it worked, reported status in HA and everything. I re-flashed the same firmware, unplugged from computer, plugged into USB power supply - nothing. Unplug, plug in, same. I unplugged and plugged in for three more times hoping for an odd solution (have you tried turning it off and on again?), but that didn’t help.

I’m a bit lost what the reason and solution could be because to my knowledge, nothing changed :thinking:

I’d appreciate it a lot if you could send me your ideas what the reason might be. I can look for debugging messages tomorrow or something if required :slightly_smiling_face:‍:arrow_up_down:

Update with Logs:

Trying to log in wirelessly:

INFO ESPHome 2024.10.3
INFO Reading configuration /config/esphome/bew-technik-esp.yaml...
WARNING GPIO12 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Starting log output from bew-technik-esp.local using esphome API
WARNING Can't connect to ESPHome API for bew-technik-esp.local: Error resolving IP address: [Errno -5] No address associated with hostname (APIConnectionError)
INFO Trying to connect to bew-technik-esp.local in the background

Plugged into computer (I downloaded and attached as well ah, you cannot upload txt files here

[09:47:32]ets Jul 29 2019 12:21:46
[09:47:32]
[09:47:32]rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[09:47:32]configsip: 0, SPIWP:0xee
[09:47:32]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[09:47:32]mode:DIO, clock div:2
[09:47:32]load:0x3fff0030,len:1184
[09:47:32]load:0x40078000,len:13132
[09:47:32]load:0x40080400,len:3036
[09:47:32]entry 0x400805e4
[09:47:32][I][logger:156]: Log initialized
[09:47:32][C][safe_mode:079]: There have been 3 suspected unsuccessful boot attempts
[09:47:32][D][esp32.preferences:114]: Saving 1 preferences to flash...
[09:47:32][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[09:47:32][I][app:029]: Running through setup()...
[09:47:32][C][wifi:048]: Setting up WiFi...
[09:47:32][C][wifi:061]: Starting WiFi...
[09:47:32][C][wifi:062]:   Local MAC: CC:7B:5C:F1:8F:34
[09:47:32][D][wifi:482]: Starting scan...
[09:47:32][W][component:157]: Component wifi set Warning flag: scanning for networks
[09:47:32][D][binary_sensor:036]: 'Bewegungssensor Technikraum': Sending state ON
[09:47:38][D][wifi:497]: Found networks:
[09:47:38][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:47:38][D][wifi:542]:     Channel: 1
[09:47:38][D][wifi:543]:     RSSI: -50 dB
[09:47:38][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:47:38][D][wifi:542]:     Channel: 1
[09:47:38][D][wifi:543]:     RSSI: -67 dB
[09:47:38][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:47:38][D][wifi:542]:     Channel: 1
[09:47:38][D][wifi:543]:     RSSI: -70 dB
[09:47:38][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:47:38][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:47:38][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:47:40][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Authentication Failed'
[09:47:40][W][wifi:674]: WiFi Unknown connection status 0
[09:47:40][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:47:40][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Association Failed'
[09:47:40][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Authentication Failed'
[09:47:45][D][wifi:482]: Starting scan...
[09:47:51][D][wifi:497]: Found networks:
[09:47:51][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:47:51][D][wifi:542]:     Channel: 1
[09:47:51][D][wifi:543]:     RSSI: -68 dB
[09:47:51][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:47:51][D][wifi:542]:     Channel: 1
[09:47:51][D][wifi:543]:     RSSI: -70 dB
[09:47:51][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:47:51][D][wifi:542]:     Channel: 1
[09:47:51][D][wifi:543]:     RSSI: -50 dB
[09:47:51][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:47:51][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:47:51][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:47:51][W][wifi:653]: Error while connecting to network.
[09:47:51][D][wifi:697]: Retrying with hidden networks...
[09:47:51][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:47:51][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[09:47:56][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:47:56][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[09:47:56][D][wifi:697]: Retrying with hidden networks...
[09:47:56][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:47:56][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[09:47:56][D][wifi:697]: Retrying with hidden networks...
[09:47:58][D][esp-idf:000][wifi]: E (33260) wifi:
[09:47:58][D][esp-idf:000][wifi]: Association refused temporarily, comeback time 1024 mSec
[09:47:58][D][esp-idf:000][wifi]: 

[09:48:01][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:01][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Authentication Failed'
[09:48:01][W][wifi:690]: Restarting WiFi adapter...
[09:48:01][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:03][W][wifi:674]: WiFi Unknown connection status 0
[09:48:08][D][wifi:482]: Starting scan...
[09:48:12][D][binary_sensor:036]: 'Bewegungssensor Technikraum': Sending state OFF
[09:48:14][D][wifi:497]: Found networks:
[09:48:14][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:48:14][D][wifi:542]:     Channel: 1
[09:48:14][D][wifi:543]:     RSSI: -66 dB
[09:48:14][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:48:14][D][wifi:542]:     Channel: 1
[09:48:14][D][wifi:543]:     RSSI: -50 dB
[09:48:14][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:48:14][D][wifi:542]:     Channel: 1
[09:48:14][D][wifi:543]:     RSSI: -67 dB
[09:48:14][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:48:14][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:48:14][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:14][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Association Leave'
[09:48:14][W][wifi:674]: WiFi Unknown connection status 0
[09:48:14][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:15][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Authentication Failed'
[09:48:17][D][binary_sensor:036]: 'Bewegungssensor Technikraum': Sending state ON
[09:48:20][D][wifi:482]: Starting scan...
[09:48:27][D][wifi:497]: Found networks:
[09:48:27][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:48:27][D][wifi:542]:     Channel: 1
[09:48:27][D][wifi:543]:     RSSI: -48 dB
[09:48:27][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:48:27][D][wifi:542]:     Channel: 1
[09:48:27][D][wifi:543]:     RSSI: -66 dB
[09:48:27][I][wifi:541]: - 'HouseLANister' [redacted]β–‚β–„β–†β–ˆ
[09:48:27][D][wifi:542]:     Channel: 1
[09:48:27][D][wifi:543]:     RSSI: -67 dB
[09:48:27][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:48:27][D][wifi:546]: - [redacted] [redacted]β–‚β–„β–†β–ˆ
[09:48:27][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:27][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Association Leave'
[09:48:27][W][wifi:674]: WiFi Unknown connection status 0
[09:48:27][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:28][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Authentication Failed'
[09:48:28][D][wifi:697]: Retrying with hidden networks...
[09:48:29][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Auth Expired'
[09:48:32][I][wifi:182]: Starting fallback AP!
[09:48:32][C][wifi:263]: Setting up AP...
[09:48:32][C][wifi:265]:   AP SSID: 'Bew-Technik-Esp Fallback Hotspot'
[09:48:32][C][wifi:266]:   AP Password: '7EHlOFxa7Qsk'
[09:48:34][C][wifi:275]:   IP Address: 192.168.4.1
[09:48:34][C][api:026]: Setting up Home Assistant API server...
[09:48:34][I][app:062]: setup() finished successfully!
[09:48:34][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:34][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[09:48:34][D][esp32.preferences:114]: Saving 1 preferences to flash...
[09:48:34][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[09:48:34][W][component:157]: Component api set Warning flag: unspecified
[09:48:34][I][app:100]: ESPHome version 2024.10.3 compiled on Nov 17 2024, 09:44:38
[09:48:34][C][wifi:600]: WiFi:
[09:48:34][C][wifi:428]:   Local MAC: CC:7B:5C:F1:8F:34
[09:48:34][C][wifi:433]:   SSID: [redacted]
[09:48:34][C][wifi:440]:   BSSID: [redacted]
[09:48:34][C][wifi:441]:   Hostname: 'bew-technik-esp'
[09:48:34][C][wifi:443]:   Signal strength: 0 dB β–‚β–„β–†β–ˆ
[09:48:34][C][wifi:447]:   Channel: 1
[09:48:34][C][wifi:448]:   Subnet: 0.0.0.0
[09:48:34][C][wifi:449]:   Gateway: 0.0.0.0
[09:48:34][C][wifi:450]:   DNS1: 0.0.0.0
[09:48:34][C][wifi:451]:   DNS2: 0.0.0.0
[09:48:34][W][wifi:653]: Error while connecting to network.
[09:48:34][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:34][C][logger:185]: Logger:
[09:48:34][C][logger:186]:   Level: DEBUG
[09:48:34][C][logger:188]:   Log Baud Rate: 115200
[09:48:34][C][logger:189]:   Hardware UART: UART0
[09:48:34][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[09:48:34][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Bewegungssensor Technikraum'
[09:48:34][C][gpio.binary_sensor:015]:   Device Class: 'motion'
[09:48:34][C][gpio.binary_sensor:016]:   Pin: GPIO14
[09:48:34][C][captive_portal:089]: Captive Portal:
[09:48:34][C][mdns:116]: mDNS:
[09:48:34][C][mdns:117]:   Hostname: bew-technik-esp
[09:48:34][C][esphome.ota:073]: Over-The-Air updates:
[09:48:34][C][esphome.ota:074]:   Address: bew-technik-esp.local:3232
[09:48:34][C][esphome.ota:075]:   Version: 2
[09:48:34][C][esphome.ota:078]:   Password configured
[09:48:34][C][safe_mode:018]: Safe Mode:
[09:48:34][C][safe_mode:020]:   Boot considered successful after 60 seconds
[09:48:34][C][safe_mode:021]:   Invoke after 10 boot attempts
[09:48:34][C][safe_mode:023]:   Remain in safe mode for 300 seconds
[09:48:34][W][safe_mode:029]: Last reset occurred too quickly; safe mode will be invoked in 7 restarts
[09:48:34][C][api:140]: API Server:
[09:48:34][C][api:141]:   Address: bew-technik-esp.local:6053
[09:48:34][C][api:143]:   Using noise encryption: YES
[09:48:36][D][esp-idf:000][wifi]: E (71576) wifi:
[09:48:36][D][esp-idf:000][wifi]: Set status to INIT
[09:48:36][D][esp-idf:000][wifi]: 

[09:48:36][D][esp-idf:000][wifi]: E (71604) wifi:
[09:48:36][D][esp-idf:000][wifi]: Set status to INIT
[09:48:36][D][esp-idf:000][wifi]: 

[09:48:36][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Association Failed'
[09:48:39][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:39][W][wifi:653]: Error while connecting to network.
[09:48:39][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:39][W][wifi:669]: Connecting to WiFi network failed. Are the credentials wrong?
[09:48:44][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:44][W][wifi_esp32:537][arduino_events]: Event: Disconnected ssid='HouseLANister' bssid=[redacted] reason='Association Leave'
[09:48:44][W][wifi:674]: WiFi Unknown connection status 0
[09:48:44][I][wifi:313]: WiFi Connecting to 'HouseLANister'...
[09:48:46][I][wifi:617]: WiFi Connected!
[09:48:46][C][wifi:428]:   Local MAC: CC:7B:5C:F1:8F:34
[09:48:46][C][wifi:433]:   SSID: [redacted]
[09:48:46][C][wifi:436]:   IP Address: 192.168.1.212
[09:48:46][C][wifi:440]:   BSSID: [redacted]
[09:48:46][C][wifi:441]:   Hostname: 'bew-technik-esp'
[09:48:46][C][wifi:443]:   Signal strength: -48 dB β–‚β–„β–†β–ˆ
[09:48:46][C][wifi:447]:   Channel: 1
[09:48:46][C][wifi:448]:   Subnet: 255.255.248.0
[09:48:46][C][wifi:449]:   Gateway: 192.168.0.1
[09:48:46][C][wifi:450]:   DNS1: 192.168.0.1
[09:48:46][C][wifi:451]:   DNS2: 192.168.0.253
[09:48:46][D][wifi:626]: Disabling AP...
[09:48:46][W][component:237]: Component wifi took a long time for an operation (57 ms).
[09:48:46][W][component:238]: Components should block for at most 30 ms.
[09:48:46][D][api:103]: Accepted 192.168.1.100
[09:48:46][W][component:170]: Component api cleared Warning flag
[09:48:46][W][component:237]: Component api took a long time for an operation (52 ms).
[09:48:46][W][component:238]: Components should block for at most 30 ms.
[09:48:46][W][component:170]: Component wifi cleared Warning flag
[09:48:46][D][api.connection:1446]: Home Assistant 2024.11.1 (192.168.1.100): Connected successfully

The ESP code is quite simple:

esphome:
  name: bew-technik-esp
  friendly_name: BEW_Technik_ESP

esp32:
  board: esp32dev
  framework:
    type: arduino

binary_sensor:
  - platform: gpio
    pin: 12
    name: "Bewegungssensor Technikraum"
    device_class: motion
    filters:
      - delayed_off: 30000ms

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ".../...="

ota:
  - platform: esphome
    password: "..."

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Bew-Technik-Esp Fallback Hotspot"
    password: "..."

captive_portal:
    

As long as I keep the connection up in ESPhome, it’s working fine:

When I unplug the ESP from the computer and attach to a normal USB power supply, same behaviour and no connection :-/