Skip to content

Commit

Permalink
Unregistering wifi and IP event handlers before factory reset to avoi…
Browse files Browse the repository at this point in the history
…d random crashes due to post event queue failure
  • Loading branch information
shripad621git committed May 31, 2024
1 parent b3fc1d0 commit 6cbc705
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <lib/support/CodeUtils.h>
#include <platform/ConfigurationManager.h>
#include <platform/ESP32/ESP32Config.h>
#include <platform/ESP32/ESP32Utils.h>
#include <platform/internal/GenericConfigurationManagerImpl.ipp>

#if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
Expand Down Expand Up @@ -404,6 +405,19 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
CHIP_ERROR err;

// Unregistering the wifi and IP event handlers from the esp_default_event_loop()
err = ESP32Utils::MapError(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent));
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to unregister IP event handler");
}

err = ESP32Utils::MapError(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent));
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to unregister wifi event handler");
}

ChipLogProgress(DeviceLayer, "Performing factory reset");

// Erase all values in the chip-config NVS namespace.
Expand Down

0 comments on commit 6cbc705

Please sign in to comment.