1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 07:45:56 +00:00
This commit is contained in:
J. Nick Koston
2025-11-17 23:35:26 -06:00
parent 3f799a01a2
commit b9af06f5a4
4 changed files with 10 additions and 1 deletions

View File

@@ -51,7 +51,11 @@ void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
ESP_LOGI(TAG, " SSID='%s'", ssid.c_str());
ESP_LOGI(TAG, " Password=" LOG_SECRET("'%s'"), psk.c_str());
// 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); });
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();
});
request->redirect(ESPHOME_F("/?save"));
}

View File

@@ -381,6 +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();
this->connecting_sta_ = {};
this->cancel_timeout("wifi-connect-timeout");

View File

@@ -50,6 +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();
this->connecting_sta_ = {};
this->cancel_timeout("wifi-connect-timeout");
this->set_state_(improv::STATE_PROVISIONED);

View File

@@ -291,6 +291,7 @@ class WiFiComponent : public Component {
void set_passive_scan(bool passive);
void save_wifi_sta(const std::string &ssid, const std::string &password);
// ========== INTERNAL METHODS ==========
// (In most use cases you won't need these)
/// Setup WiFi interface.