esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
285 stars 34 forks source link

Using `framework: type: esp-idf` frequently disconnects from WiFi / HA unless using `wifi: power_save_mode: none` or `wifi: fast_connect: true` #5754

Open ptr727 opened 2 weeks ago

ptr727 commented 2 weeks ago

The problem

TL;DR:
When using framework: type: esp-idf the ESP32 keeps disconnecting from HA unless using wifi: fast_connect: true.

I discovered this problem when I wanted to use my first BT proxy.
I created a BT proxy using standard ESPHome devices BT proxy on a Screek BP1 ESP32.
The device kept on disconnecting / reconnecting from WiFi and / or HA.

I created a minimal configuration, no BT proxy, and through experimentation I found that:

Note: I run Ubiquity UniFi network equipment, including several Unifi v6 AP's and lots of devices, including several ESPHome devices that use the default Arduino framework, without any issues.

I verified that using framework: type: esp-idf and wifi: fast_connect: true and esp32_ble_tracker and bluetooth_proxy works.

Which version of ESPHome has the issue?

2024.4.2

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

2024.4.4

What platform are you using?

ESP32-IDF

Board

Screek Bluetooth Proxy BP1

Component causing the issue

esp-idf

Example YAML snippet

substitutions:
  device_name: esp32-test
  device_comment: "ESP32 test Device"

esphome:
  name: ${device_name}
  comment: ${device_comment}

esp32:
  board: esp32dev
  framework:
    type: esp-idf

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret wifi_domain
  reboot_timeout: 5min
  # power_save_mode: none
  fast_connect: true

logger:
  level: debug

api:
  id: api_server
  reboot_timeout: 5min

ota:
  password: !secret ota_password

time:
  - platform: homeassistant
    id: homeassistant_time

debug:
  update_interval: 60s

# esp32_ble_tracker:
#   scan_parameters:
#     active: true

# bluetooth_proxy:
#   active: true

button:
  - platform: restart
    name: ${device_name}_restart

binary_sensor:
  - platform: status
    name: ${device_name}_status

text_sensor:
  - platform: version
    name: ${device_name}_version
  - platform: wifi_info
    ip_address:
      name: ${device_name}_wifi_ip
      id: wifi_ip
      update_interval: 60s
    ssid:
      name: ${device_name}_wifi_ssid
      update_interval: 60s
    bssid:
      name: ${device_name}_wifi_bssid
      update_interval: 60s
  - platform: debug
    device:
      name: ${device_name}_device_info
    reset_reason:
      name: ${device_name}_reset_reason

sensor:
  - platform: wifi_signal
    name: ${device_name}_wifi_signal
    update_interval: 60s
  - platform: uptime
    name: ${device_name}_uptime
    unit_of_measurement: min
    filters:
      - lambda: return x / 60.0;
  - platform: debug
    free:
      name: ${device_name}_heap_free

Anything in the logs that might be useful for us?

WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.041s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.082s
[20:04:01][D][api:102]: Accepted 192.168.1.26
[20:04:01][D][api.connection:1210]: Home Assistant 2024.4.4 (192.168.1.26): Connected successfully
[20:04:01][D][time:049]: Synchronized time: 2024-04-30 20:04:01
[20:04:25][D][sensor:094]: 'esp32-test_uptime': Sending state 0.78760 min with 0 decimals of accuracy
WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.026s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.050s
WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.052s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.054s
[20:05:42][D][api:102]: Accepted 192.168.1.26
[20:05:42][D][api.connection:1210]: Home Assistant 2024.4.4 (192.168.1.26): Connected successfully
[20:05:42][D][time:049]: Synchronized time: 2024-04-30 20:05:42
[20:06:14][D][sensor:094]: 'esp32-test_uptime': Sending state 0.86745 min with 0 decimals of accuracy
WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.004s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.040s
WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.042s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.053s
[20:07:26][D][api:102]: Accepted 192.168.1.26
[20:07:26][D][api.connection:1210]: Home Assistant 2024.4.4 (192.168.1.26): Connected successfully
[20:07:26][D][time:049]: Synchronized time: 2024-04-30 20:07:26
WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.015s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.059s
[20:08:06][D][api:102]: Accepted 192.168.1.26
[20:08:06][D][api.connection:1210]: Home Assistant 2024.4.4 (192.168.1.26): Connected successfully
[20:08:06][D][time:049]: Synchronized time: 2024-04-30 20:08:06
WARNING esp32-test @ 192.168.1.181: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for esp32-test @ 192.168.1.181
WARNING Disconnected from API
INFO Successfully connected to esp32-test @ 192.168.1.181 in 0.051s
INFO Successful handshake with esp32-test @ 192.168.1.181 in 0.056s

Additional information

No response

ptr727 commented 1 week ago

Observation:

I had ruled out PSU due to testing three different PSU's (never an issue before using BT proxy), but it does seem that the PSU noise has a greater influences when using BT and WiFi on some devices with possibly inadequate power noise regulation?

pfeerick commented 1 week ago

I had been running the really early BT Proxy config... from when it was first announced... and updating to 2024.4.2 broke it... hadn't had an issue before with a ESP32-DEV board being powered off USB, hanging off a desk lamp. Tried swapping to the current config, and no change.

However, it seems like maybe it it is starting to fail, or there has been some timing changing which is causing it to brownout when both bluetooth and WiFi are started... as I swapped it with another ESP32-DEV, and that one is working. Adding capacitors to either VCC/3V3 made no change, but disabling the bluetooth-proxy did restore it to functioning :shrug: Pretty sure I had 2024.4.1 on it before.

ptr727 commented 1 week ago

However, it seems like maybe it it is starting to fail

Did you try fast_connect: true to see if it made a difference?