Skip to content

Commit

Permalink
Fix Disconnect RPC for ESP 32 (#26231)
Browse files Browse the repository at this point in the history
* Fix Disconnect RPC for ESP 32

* Restyle
  • Loading branch information
tehampson authored and pull[bot] committed Jul 31, 2023
1 parent a8b077d commit 1017295
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/platform/esp32/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ class Esp32WiFi final : public WiFi
size_t password_size = std::min(sizeof(password) - 1, static_cast<size_t>(request.secret.size));
memcpy(password, request.secret.bytes, password_size);
password[password_size] = '\0';
if (chip::DeviceLayer::NetworkCommissioning::ESPWiFiDriver::GetInstance().ConnectWiFiNetwork(
ssid, strlen(ssid), password, strlen(password)) != CHIP_NO_ERROR)
chip::DeviceLayer::PlatformMgr().LockChipStack();
CHIP_ERROR error = chip::DeviceLayer::NetworkCommissioning::ESPWiFiDriver::GetInstance().ConnectWiFiNetwork(
ssid, strlen(ssid), password, strlen(password));
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
if (error != CHIP_NO_ERROR)
{
return pw::Status::Internal();
}
Expand All @@ -214,8 +217,9 @@ class Esp32WiFi final : public WiFi

pw::Status Disconnect(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision();
chip::DeviceLayer::ConnectivityMgr().SetWiFiStationMode(chip::DeviceLayer::ConnectivityManager::kWiFiStationMode_Disabled);
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
return pw::OkStatus();
}

Expand Down
6 changes: 6 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ void ConnectivityManagerImpl::_ClearWiFiStationProvision(void)
{
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled)
{
CHIP_ERROR error = chip::DeviceLayer::Internal::ESP32Utils::ClearWiFiStationProvision();
if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ClearWiFiStationProvision failed: %s", chip::ErrorStr(error));
return;
}
DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL);
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP
DeviceLayer::SystemLayer().ScheduleWork(DriveAPState, NULL);
Expand Down

0 comments on commit 1017295

Please sign in to comment.