diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index 2871c4c3f2031d..b554014b77bbf9 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -236,6 +236,17 @@ CHIP_ERROR ESPWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, return ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Enabled); } +CHIP_ERROR ESPWiFiDriver::DisconnectDriver() +{ + if (chip::DeviceLayer::Internal::ESP32Utils::IsStationProvisioned()) + { + ReturnErrorOnFailure(BackupConfiguration()); + // Attaching to an empty network will disconnect the network. + ReturnErrorOnFailure(ConnectWiFiNetwork(nullptr, 0, nullptr, 0)); + } + return CHIP_NO_ERROR; +} + void ESPWiFiDriver::OnConnectWiFiNetwork() { if (mpConnectCallback) diff --git a/src/platform/ESP32/NetworkCommissioningDriver.h b/src/platform/ESP32/NetworkCommissioningDriver.h index 447d6346dcbd1c..734088626f7603 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.h +++ b/src/platform/ESP32/NetworkCommissioningDriver.h @@ -103,6 +103,7 @@ class ESPWiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; + CHIP_ERROR DisconnectDriver() override; Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override;