#19459·esphome

Fallback AP never restarts after first STA reconnect in same boot (`ap_setup_` never cleared) — root cause of esphome/issues#5759

Author: gcatroCreated Sep 22, 2026Updated Sep 27, 2026

The problem

The problem

The fallback AP starts at most once per boot. If the device loses its STA network, the AP correctly starts after ap_timeout (90 s). If the STA network then returns, the device reconnects and shuts the AP down. If the STA network is lost a second time in the same boot, the AP never starts again, however long the device waits. A reboot restores the behaviour, once.

This is the behaviour reported in esphome/issues#5759 (2024.4.1, still open, marked stale). It is still present in 2026.9.0, and the cause appears to be the following.

Root cause (line numbers from 2026.9.0)

components/wifi/wifi_component.cpp

  • Line 880, fallback check in loop(): if (this->has_ap() && !this->ap_setup_ && !provisioning_closed)
  • Line 1007, in setup_ap_config_(): this->ap_setup_ = this->wifi_start_ap_(this->ap_);
  • Around line 1644, on successful STA connection: ESP_LOGD(TAG, "Disabling AP"); this->wifi_mode_({}, false);

ap_setup_ is set to true when the AP first starts and is never reset. When the AP is disabled after a successful connection, ap_setup_ stays true, so the fallback condition at line 880 can never be satisfied again in that boot. (ap_started_, which tracks the real AP state, is correctly cleared at wifi_component_esp_idf.cpp:1007.)

Suggested fix

Either reset ap_setup_ = false where the AP is disabled on connect, or gate the fallback on the real AP state (!this->is_ap_active()) rather than ap_setup_. Note setup_ap_config_() also returns early at line 976 when ap_setup_ is true, so that guard would need the same treatment.

Why it matters

The fallback AP is the recovery path when a site's Wi-Fi password or router changes. With this bug, any unit that has had one earlier outage in its current boot becomes unreachable without a serial connection.

Workaround

A YAML interval that calls App.safe_reboot() when the device has had neither STA (is_connected()) nor an active AP (is_ap_active()) for 5 minutes. The fresh boot re-arms the AP. Tested and working.

Which version of ESPHome has the issue?

2026.9.0 (also reported on 2024.4.1 in esphome/issues#5759)

What type of installation are you using?

pip (CLI) on Windows

What platform are you using?

ESP32-S3

Board

Seeed reTerminal E1002 (ESP32-S3R8)

Component causing the issue

wifi

Example YAML snippet

yaml
esphome:
  name: ap-test

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

logger:

wifi:
  ssid: "your-ssid"
  password: "your-password"
  ap:
    ssid: "ap-test-setup"
    password: "setup-password"

captive_portal:

Steps to reproduce

  1. Boot with the STA network available; device connects.
  2. Turn the STA network off. After ~90 s: Starting fallback AP.
  3. Turn the STA network on. Device reconnects: Disabling AP.
  4. Turn the STA network off again. Starting fallback AP never appears.

Anything in the logs that might be useful for us?

Second outage in the same boot (uptime ~26 min, per the IDF timestamp). The AP is never restarted; the device loops scan / hidden retry / adapter restart indefinitely:

[10:21:33.640][W][wifi_esp32:869]: Disconnected ssid='<ssid>' bssid=<redacted> reason='Beacon Timeout'
[10:21:33.651][I][esp-idf:000]: E (1564243) transport_base: poll_write select error 113 ...
[10:21:33.670][W][wifi:833]: Connection lost; reconnecting
...
[10:27:06.051][W][wifi:1559]: No matching network found
[10:27:06.062][I][wifi:1145]: Connecting to '<ssid>' (any) (priority 0, attempt 1/1 in phase RETRY_HIDDEN)...
[10:27:08.476][W][wifi_esp32:860]: Disconnected ssid='<ssid>' reason='Probe Request Unsuccessful'
[10:27:08.485][W][wifi:759]: Restarting adapter
[10:27:08.987][W][wifi:1740]: Network no longer found

Additional information

Reproduced deliberately with a serial log running: first outage after a power cycle produced Starting fallback AP at ~90 s; after reconnect, a second outage produced no AP until the workaround rebooted the device.

Which version of ESPHome has the issue?

2026.9.0

What type of installation are you using?

Docker

What platform are you using?

ESP32

Component causing the issue

WIFI

YAML Config

yaml
esphome:
  name: ap-test

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

# Serial on this board goes through a CH340 bridge on UART0, not native USB.
logger:
  hardware_uart: UART0
  level: DEBUG

wifi:
  ssid: "your-ssid"
  password: "your-password"
  ap:
    ssid: "ap-test-setup"
    password: "setup-password"

captive_portal:

Anything in the logs that might be useful for us?

txt

Additional information

No response