This commit is contained in:
J. Nick Koston
2025-11-17 23:43:33 -06:00
parent b9af06f5a4
commit 29ef0a6740
5 changed files with 17 additions and 6 deletions

View File

@@ -53,8 +53,8 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
// Defer save to main loop thread to avoid NVS operations from HTTP thread
this->defer([ssid, psk]() {
wifi::global_wifi_component->save_wifi_sta(ssid, psk);
// Trigger immediate retry to attempt connection with new credentials
wifi::global_wifi_component->retry_connect();
// Trigger connection attempt (exits cooldown if needed)
wifi::global_wifi_component->connect_soon();
});
request->redirect(ESPHOME_F("/?save"));
}

View File

@@ -381,8 +381,8 @@ void ESP32ImprovComponent::check_wifi_connection_() {
if (this->state_ == improv::STATE_PROVISIONING) {
wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(), this->connecting_sta_.get_password());
// Trigger immediate retry to attempt connection with new credentials
wifi::global_wifi_component->retry_connect();
// Trigger connection attempt (exits cooldown if needed, no-op if already connected)
wifi::global_wifi_component->connect_soon();
this->connecting_sta_ = {};
this->cancel_timeout("wifi-connect-timeout");

View File

@@ -50,8 +50,8 @@ void ImprovSerialComponent::loop() {
if (wifi::global_wifi_component->is_connected()) {
wifi::global_wifi_component->save_wifi_sta(this->connecting_sta_.get_ssid(),
this->connecting_sta_.get_password());
// Trigger immediate retry to attempt connection with new credentials
wifi::global_wifi_component->retry_connect();
// Trigger connection attempt (exits cooldown if needed, no-op if already connected)
wifi::global_wifi_component->connect_soon();
this->connecting_sta_ = {};
this->cancel_timeout("wifi-connect-timeout");
this->set_state_(improv::STATE_PROVISIONED);

View File

@@ -676,6 +676,14 @@ void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &pa
this->force_scan_after_provision_ = true;
}
void WiFiComponent::connect_soon() {
// Only trigger retry if we're in cooldown - if already connecting/connected, do nothing
if (this->state_ == WIFI_COMPONENT_STATE_COOLDOWN) {
ESP_LOGD(TAG, "Exiting cooldown early due to new WiFi credentials");
this->retry_connect();
}
}
void WiFiComponent::start_connecting(const WiFiAP &ap) {
// Log connection attempt at INFO level with priority
char bssid_s[18];

View File

@@ -292,6 +292,9 @@ class WiFiComponent : public Component {
void save_wifi_sta(const std::string &ssid, const std::string &password);
/// Trigger connection attempt soon (exits cooldown if needed, otherwise no-op if already connecting/connected)
void connect_soon();
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
/// Setup WiFi interface.