Skip to content

Commit da57c2e

Browse files
authored
[Telink] fix commissioning after last fabric removed and improve BLE stability (project-chip#67831)
1 parent ea50337 commit da57c2e

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

config/telink/chip-module/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ config TFLM_FEATURE
282282

283283
choice CHIP_LAST_FABRIC_REMOVED_ACTION
284284
prompt "An action to perform after removing the last fabric"
285-
default CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
285+
default CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY
286286

287287
config CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
288288
bool "After removing the last fabric erase NVS and reboot"

config/telink/chip-module/Kconfig.defaults

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ if BT
139139
config BT_PERIPHERAL
140140
default y
141141

142+
config BT_PERIPHERAL_PREF_MIN_INT
143+
default 36
144+
145+
config BT_PERIPHERAL_PREF_MAX_INT
146+
default 36
147+
148+
# Increase BT timeout to 5 s to improve connection reliability and avoid fast drop outs.
149+
config BT_PERIPHERAL_PREF_TIMEOUT
150+
default 500
151+
152+
config BT_GAP_AUTO_UPDATE_CONN_PARAMS
153+
default y
154+
155+
# Decrease connection parameters update time, as some Matter controllers request
156+
# enabling IP networking faster than BT connection parameters are updated, what may result
157+
# in commissioning instabilities.
158+
config BT_CONN_PARAM_UPDATE_TIMEOUT
159+
default 1000
160+
142161
config BT_GATT_DYNAMIC_DB
143162
default y
144163

examples/platform/telink/util/include/FabricTableDelegate.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <app/server/Server.h>
2222
#include <zephyr/fs/nvs.h>
2323
#include <zephyr/settings/settings.h>
24-
#include <zephyr/sys/reboot.h>
2524
#ifdef CONFIG_CHIP_WIFI
2625
#include "WiFiManager.h"
2726
#endif
@@ -46,6 +45,13 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
4645

4746
if (server.GetFabricTable().FabricCount() == 0)
4847
{
48+
// ScheduleFactoryReset in case of failed commissioning
49+
if (AppTaskCommon::IsCommissioningFailed())
50+
{
51+
chip::Server::GetInstance().ScheduleFactoryReset();
52+
return;
53+
}
54+
4955
if (chip::DeviceLayer::ConnectivityMgr().IsBLEAdvertisingEnabled())
5056
{
5157
server.GetCommissioningWindowManager().CloseCommissioningWindow();
@@ -63,9 +69,8 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
6369
{
6470
LogErrorOnFailure(chip::DeviceLayer::PlatformMgr().ScheduleWork([](intptr_t) {
6571
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
66-
#ifdef CONFIG_CHIP_WIFI
6772
chip::Server::GetInstance().ScheduleFactoryReset();
68-
#else
73+
#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY)
6974
ChipLogProgress(DeviceLayer, "Erasing settings partition");
7075
// TC-OPCREDS-3.6 (device doesn't need to reboot automatically after the last fabric is removed) can't use
7176
// FactoryReset
@@ -89,14 +94,7 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
8994
#ifdef CONFIG_TFLM_FEATURE
9095
AppTask::MicroSpeechProcessStop();
9196
#endif
92-
// Reboot in case of failed commissioning to allow new pairing via BLE
93-
if (AppTaskCommon::IsCommissioningFailed())
94-
{
95-
ChipLogProgress(DeviceLayer, "Rebooting board");
96-
sys_reboot(SYS_REBOOT_WARM);
97-
}
98-
#endif // CONFIG_CHIP_WIFI
99-
#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY) || defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
97+
#elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
10098
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
10199
LogErrorOnFailure(chip::DeviceLayer::ThreadStackMgr().ClearAllSrpHostAndServices());
102100
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
@@ -112,7 +110,6 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
112110
LogErrorOnFailure(chip::DeviceLayer::WiFiManager::Instance().Disconnect());
113111
chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision();
114112
#endif
115-
#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
116113
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
117114
LogErrorOnFailure(chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false));
118115
LogErrorOnFailure(chip::DeviceLayer::PlatformMgr().ScheduleWork(StartThreadPrescan, 0));
@@ -127,7 +124,6 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
127124
}
128125
ChipLogError(FabricProvisioning, "Could not start Bluetooth LE advertising");
129126
#endif
130-
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
131127
#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
132128
}));
133129
}

0 commit comments

Comments
 (0)