Merge ln882x-shutdown-disconnect; LN882x checks association before leaving the AP

This commit is contained in:
J. Nick Koston
2026-10-04 21:59:40 -05:00
3 changed files with 10 additions and 6 deletions
+5 -4
View File
@@ -768,14 +768,15 @@ void WiFiComponent::restart_adapter() {
void WiFiComponent::on_powerdown() {
// Leave the AP so it no longer holds the association when we come back.
#ifdef USE_LN882X
if (!this->wifi_powerdown_disconnect_())
return;
#else
if (!this->is_connected())
return;
ESP_LOGD(TAG, "Disconnecting before powerdown");
#ifdef USE_LN882X
this->wifi_powerdown_disconnect_();
#else
this->wifi_disconnect_();
#endif
ESP_LOGD(TAG, "Disconnected before powerdown");
delay(100); // NOLINT: once per reboot or deep sleep, lets the deauth go out
}
+1 -1
View File
@@ -793,7 +793,7 @@ class WiFiComponent final : public Component {
bool wifi_disconnect_();
#ifdef USE_LN882X
void wifi_powerdown_disconnect_();
bool wifi_powerdown_disconnect_();
#endif
network::IPAddress wifi_subnet_mask_();
@@ -790,8 +790,11 @@ network::IPAddress WiFiComponent::wifi_soft_ap_ip() { return {WiFi.softAPIP()};
#endif // USE_WIFI_AP
#ifdef USE_LN882X
void WiFiComponent::wifi_powerdown_disconnect_() {
bool WiFiComponent::wifi_powerdown_disconnect_() {
if (WiFi.status() != WL_CONNECTED) // associated, even before DHCP has finished
return false;
wifi_sta_disconnect(); // not WiFi.disconnect(): it frees the SSID its event handlers read
return true;
}
#endif