diff --git a/examples/all-clusters-app/mbed/main/AppTask.cpp b/examples/all-clusters-app/mbed/main/AppTask.cpp index 97946f86ab6326..6952a360aa82d9 100644 --- a/examples/all-clusters-app/mbed/main/AppTask.cpp +++ b/examples/all-clusters-app/mbed/main/AppTask.cpp @@ -59,13 +59,6 @@ int AppTask::Init() }, 0); - // Start BLE advertising if needed - if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART) - { - ChipLogProgress(NotSpecified, "Enabling BLE advertising."); - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - } - chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement(); // Init ZCL Data Model and start server diff --git a/examples/lighting-app/mbed/main/AppTask.cpp b/examples/lighting-app/mbed/main/AppTask.cpp index 21750f22a1a6e1..6e8f8180f2e90f 100644 --- a/examples/lighting-app/mbed/main/AppTask.cpp +++ b/examples/lighting-app/mbed/main/AppTask.cpp @@ -116,13 +116,6 @@ int AppTask::Init() LightingMgr().Init(MBED_CONF_APP_LIGHTING_STATE_LED); LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted); - // Start BLE advertising if needed - if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART) - { - ChipLogProgress(NotSpecified, "Enabling BLE advertising."); - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - } - chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement(); // Init ZCL Data Model and start server @@ -380,7 +373,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) return; // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, initiate factory reset - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) { ChipLogProgress(NotSpecified, "Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); @@ -418,17 +411,29 @@ void AppTask::FunctionHandler(AppEvent * aEvent) { sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - sAppTask.mFunction = kFunction_SoftwareUpdate; + sAppTask.mFunction = kFunction_StartBleAdv; } } else { // If the button was released before factory reset got initiated, trigger a software update. - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) { sAppTask.CancelTimer(); sAppTask.mFunction = kFunction_NoneSelected; - ChipLogError(NotSpecified, "Software Update not supported."); + + chip::Server::GetInstance().GetFabricTable().DeleteAllFabrics(); + + if (ConnectivityMgr().IsBLEAdvertisingEnabled()) + { + ChipLogProgress(NotSpecified, "BLE advertising is already enabled"); + return; + } + + if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR) + { + ChipLogProgress(NotSpecified, "OpenBasicCommissioningWindow() failed"); + } } else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) { diff --git a/examples/lighting-app/mbed/main/include/AppTask.h b/examples/lighting-app/mbed/main/include/AppTask.h index 06014ff90bf4ab..1abd6380677e3f 100644 --- a/examples/lighting-app/mbed/main/include/AppTask.h +++ b/examples/lighting-app/mbed/main/include/AppTask.h @@ -61,6 +61,7 @@ class AppTask { kFunction_NoneSelected = 0, kFunction_SoftwareUpdate = 0, + kFunction_StartBleAdv = 1, kFunction_FactoryReset, kFunction_Invalid diff --git a/examples/lock-app/mbed/main/AppTask.cpp b/examples/lock-app/mbed/main/AppTask.cpp index 9e3a69d08f4306..e4ec43f298e681 100644 --- a/examples/lock-app/mbed/main/AppTask.cpp +++ b/examples/lock-app/mbed/main/AppTask.cpp @@ -120,13 +120,6 @@ int AppTask::Init() BoltLockMgr().Init(); BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); - // Start BLE advertising if needed - if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART) - { - ChipLogProgress(NotSpecified, "Enabling BLE advertising."); - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - } - chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement(); // Init ZCL Data Model and start server @@ -370,7 +363,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) return; // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, initiate factory reset - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) { ChipLogProgress(NotSpecified, "Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); @@ -415,17 +408,29 @@ void AppTask::FunctionHandler(AppEvent * aEvent) { sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - sAppTask.mFunction = kFunction_SoftwareUpdate; + sAppTask.mFunction = kFunction_StartBleAdv; } } else { // If the button was released before factory reset got initiated, trigger a software update. - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) { sAppTask.CancelTimer(); sAppTask.mFunction = kFunction_NoneSelected; - ChipLogError(NotSpecified, "Software Update not supported."); + + chip::Server::GetInstance().GetFabricTable().DeleteAllFabrics(); + + if (ConnectivityMgr().IsBLEAdvertisingEnabled()) + { + ChipLogProgress(NotSpecified, "BLE advertising is already enabled"); + return; + } + + if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR) + { + ChipLogProgress(NotSpecified, "OpenBasicCommissioningWindow() failed"); + } } else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) { diff --git a/examples/lock-app/mbed/main/include/AppTask.h b/examples/lock-app/mbed/main/include/AppTask.h index 355c6e32dc38ab..98a43023035f9e 100644 --- a/examples/lock-app/mbed/main/include/AppTask.h +++ b/examples/lock-app/mbed/main/include/AppTask.h @@ -59,6 +59,7 @@ class AppTask { kFunction_NoneSelected = 0, kFunction_SoftwareUpdate = 0, + kFunction_StartBleAdv = 1, kFunction_FactoryReset, kFunction_Invalid