WiFi won't connect - Heltec Wifi Kit 32 v2 (ESP32)

Hi all, I have a 4_WAY_HANDSHAKE_TIMEOUT error constantly with this Heltec Wifi Kit 32 v2. It works fine on Tasmota and stock Arduino sketches. Here’s the verbose log, I’ve done my best google-fu with no luck.

No other device, HA or otherwise, has ever given me any problems on this router. It’s a Netgear R6700v3 that’s updated. The 2.4Ghz network is running at 20Mhz on the clearest channel I could find.

Here’s my whole yaml:

esphome:
  name: water-heater-power-monitor

esp32:
  board: heltec_wifi_kit_32_v2
  framework:
    type: arduino

# Enable logging
logger:
 level: verbose

# Enable Home Assistant API
api:

ota:
  password: "47d6e963b2d7675822e15167d3bde4bf"

web_server:
 port: 80

captive_portal:

wifi:
  power_save_mode: none
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 3min

  
  manual_ip:
    static_ip: 192.168.1.100
    gateway: 192.168.1.1
    subnet: 255.255.255.0
 
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Water-Heater-Power-Monitor"
    password: "12345678"

sensor:
  - platform: pulse_meter
    name: 'Water Heater - Power Consumption'
    id: sensor_energy_pulse_meter
    unit_of_measurement: 'W'
    state_class: measurement
    device_class: power
    icon: mdi:flash-outline
    accuracy_decimals: 0
    pin: 35
    # internal_filter: 100ms

text_sensor:
  - platform: wifi_info
    ip_address:
      id: IP
    ssid:
      id: SSID

font:
  - file: "fonts/Roboto-Regular.ttf"
    id: font1
    size: 12
  - file: "fonts/Roboto-Regular.ttf"
    id: font2
    size: 8

i2c:
  sda: 4
  scl: 15

display:
  platform: ssd1306_i2c
  model: "SSD1306 128x64"
  reset_pin: 16
  address: 0x3C
  lambda: |-
   it.print( 64,0, (font1), TextAlign::TOP_CENTER, "Power Monitor");
   it.printf( 23,50, (font2), "IP: %s", id(IP).state.c_str());
   it.printf( 90,50, (font2), "SSID: %s", id(SSID).state.c_str());

And the verbose log:

[I][logger:214]: Log initialized
[C][ota:461]: There have been 1 suspected unsuccessful boot attempts.
[D][esp32.preferences:114]: Saving preferences to flash...
[I][app:029]: Running through setup()...
[V][app:030]: Sorting components by setup priority...
[I][i2c.arduino:161]: Performing I2C bus recovery
[V][i2c.arduino:033]: Scanning i2c bus for active devices...
[C][ssd1306_i2c:010]: Setting up I2C SSD1306...
[C][wifi:037]: Setting up WiFi...
[V][esp32.preferences:057]: nvs_get_blob('20045679'): ESP_ERR_NVS_NOT_FOUND - the key might not be set yet
[V][wifi_esp32:039]: Enabling STA.
[V][esp-idf:000]: I (349) wifi:
[V][esp-idf:000]: wifi driver task: 3ffaf548, prio:23, stack:3584, core=0
[V][esp-idf:000]: 

[V][esp-idf:000]: I (933) wifi:
[V][esp-idf:000]: wifi firmware version: dc30037
[V][esp-idf:000]: 

[V][esp-idf:000]: I (935) wifi:
[V][esp-idf:000]: config NVS flash: enabled
[V][esp-idf:000]: <s>Text</s>

[V][esp-idf:000]: I (946) wifi:
[V][esp-idf:000]: config nano formating: disabled
[V][esp-idf:000]: 

[V][esp-idf:000]: I (958) wifi:
[V][esp-idf:000]: Init data frame dynamic rx buffer num: 32
[V][esp-idf:000]: 

[V][esp-idf:000]: I (971) wifi:
[V][esp-idf:000]: Init management frame dynamic rx buffer num: 32
[V][esp-idf:000]: 

[V][esp-idf:000]: I (984) wifi:
[V][esp-idf:000]: Init management short buffer num: 32
[V][esp-idf:000]: 

[V][esp-idf:000]: I (997) wifi:
[V][esp-idf:000]: Init dynamic tx buffer num: 32
[V][esp-idf:000]: 

[V][esp-idf:000]: I (1009) wifi:
[V][esp-idf:000]: Init static rx buffer size: 1600
[V][esp-idf:000]: 

[V][esp-idf:000]: I (1021) wifi:
[V][esp-idf:000]: Init static rx buffer num: 16
[V][esp-idf:000]: 

[V][esp-idf:000]: I (1033) wifi:
[V][esp-idf:000]: Init dynamic rx buffer num: 32
[V][esp-idf:000]: 

[V][esp-idf:000]: I (1148) wifi:
[V][esp-idf:000]: mode : sta (30:c6:f7:14:32:5c)
[V][esp-idf:000]: 

[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START
[V][wifi_esp32:460]: Event: WiFi STA start
[V][wifi_esp32:445]: Event: WiFi ready
[V][esp-idf:000]: I (1180) wifi:
[V][esp-idf:000]: Set ps type: 0

[V][esp-idf:000]: 

[D][wifi:373]: Starting scan...
[V][component:199]: Component ssd1306_base took a long time for an operation (0.22 s).
[V][component:200]: Components should block for at most 20-30ms.
[V][sensor:074]: 'Water Heater - Power Consumption': Received new state 0.000000
[D][sensor:125]: 'Water Heater - Power Consumption': Sending state 0.00000 W with 0 decimals of accuracy
[V][component:199]: Component ssd1306_base took a long time for an operation (0.22 s).
[V][component:200]: Components should block for at most 20-30ms.
[V][component:199]: Component ssd1306_base took a long time for an operation (0.22 s).
[V][component:200]: Components should block for at most 20-30ms.
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
[V][wifi_esp32:454]: Event: WiFi Scan Done status=0 number=6 scan_id=128
[D][wifi:388]: Found networks:
[I][wifi:432]: - 'slark' (B0:39:56:4F:4B:89) [redacted]▂▄▆█
[D][wifi:433]:     Channel: 7
[D][wifi:434]:     RSSI: -48 dB
[D][wifi:437]: - '12fe12db4fea283cfdd98199b904f54e'[redacted] () [redacted]▂▄▆█
[D][wifi:437]: - 'Loud'[redacted] () [redacted]▂▄▆█
[D][wifi:437]: - ''[redacted] () [redacted]▂▄▆█
[D][wifi:437]: - 'PS4-8422831B95FC'[redacted] () [redacted]▂▄▆█
[D][wifi:437]: - 'House Router'[redacted] () [redacted]▂▄▆█
[I][wifi:248]: WiFi Connecting to 'slark'...
[V][wifi:250]: Connection Params:
[V][wifi:251]:   SSID: 'slark'
[V][wifi:254]:   BSSID: xxxxx
[V][wifi:274]:   Password: ''[redacted]
[V][wifi:279]:   Channel: 7
[V][wifi:286]:   Manual IP: Static IP=192.168.1.100 Gateway=192.168.1.1 Subnet=255.255.255.0 DNS1=0.0.0.0 DNS2=0.0.0.0
[V][wifi:290]:   Hidden: NO
[V][esp-idf:000]: I (3441) wifi:
[V][esp-idf:000]: new:<7,2>, old:<1,0>, ap:<255,255>, sta:<7,2>, prof:1
[V][esp-idf:000]: 

[V][esp-idf:000]: I (4185) wifi:
[V][esp-idf:000]: state: init -> auth (b0)
[V][esp-idf:000]: 

[V][esp-idf:000]: I (4204) wifi:
[V][esp-idf:000]: state: auth -> assoc (0)
[V][esp-idf:000]: 

[V][esp-idf:000]: I (4220) wifi:
[V][esp-idf:000]: state: assoc -> run (10)
[V][esp-idf:000]: 

[V][component:199]: Component ssd1306_base took a long time for an operation (0.59 s).
[V][component:200]: Components should block for at most 20-30ms.
[V][component:199]: Component ssd1306_base took a long time for an operation (0.22 s).
[V][component:200]: Components should block for at most 20-30ms.
[V][component:199]: Component ssd1306_base took a long time for an operation (0.22 s).
[V][component:200]: Components should block for at most 20-30ms.
[V][component:199]: Component ssd1306_base took a long time for an operation (0.22 s).
[V][component:200]: Components should block for at most 20-30ms.
[V][esp-idf:000]: I (7316) wifi:
[V][esp-idf:000]: state: run -> init (fc0)
[V][esp-idf:000]: 

[V][esp-idf:000]: I (7317) wifi:
[V][esp-idf:000]: new:<7,0>, old:<7,2>, ap:<255,255>, sta:<7,2>, prof:1
[V][esp-idf:000]: 

[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:391] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
[W][wifi_esp32:495]: Event: Disconnected ssid='slark' bssid=B0:39:56:4F:4B:89[redacted] reason='4-Way Handshake Timeout'
[W][wifi:557]: WiFi Unknown connection status 0

Does anyone have a clue as to what’s going on here? How could I fix it? Thanks!

As a last ditch effort, I double checked my router’s time, which was accurate, but decided to change it to time.nist.gov for NTP. Now this ESP32 is connecting. I had rebooted the router at least four times previously this evening with no change.

This makes no sense.

I assume you are using the v2022.2.x version of ESPHome.

With this version I also had problems with wifi connection in combination with a ssd1306 screen. Using a higher frequency (non-default) for the i2c component solved my problem.

i2c:
  sda: 4
  scl: 15
  frequency: 800kHz

You can also use other values for the frequency, if your i2c device is not supporting this one, see I²C Bus — ESPHome

1 Like

Hello, in the coding you gave, the ip address only gives the ip address of the programmed card. I want to show the ip address of the device (Raspberry) on which HA is installed. How can I do it?