|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Codex <codex@example.com> |
| 3 | +Date: Thu, 23 Apr 2026 17:45:00 +0200 |
| 4 | +Subject: [PATCH 2/3] light: keep Thread node as FED until fabric commit |
| 5 | + |
| 6 | +The esp-matter core brings every Thread FTD build up as router-eligible. |
| 7 | +For initial commissioning on a busy mesh, that allows the node to change |
| 8 | +parent and promote from child to router during the BLE-to-operational |
| 9 | +handoff. Keep uncommissioned nodes as FullEndDevice during onboarding, |
| 10 | +then restore router eligibility once the fabric is committed. |
| 11 | +--- |
| 12 | + esp-matter/examples/light/main/app_main.cpp | 54 ++++++++++++++++++++ |
| 13 | + 1 file changed, 54 insertions(+) |
| 14 | + |
| 15 | +diff --git a/examples/light/main/app_main.cpp b/examples/light/main/app_main.cpp |
| 16 | +--- a/examples/light/main/app_main.cpp |
| 17 | ++++ b/examples/light/main/app_main.cpp |
| 18 | +@@ -20,6 +20,7 @@ |
| 19 | + #include <app_priv.h> |
| 20 | + #include <app_reset.h> |
| 21 | + #if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| 22 | ++#include <platform/CHIPDeviceLayer.h> |
| 23 | + #include <platform/ESP32/OpenthreadLauncher.h> |
| 24 | + #endif |
| 25 | + |
| 26 | +@@ -46,7 +47,46 @@ |
| 27 | + using namespace chip::app::Clusters; |
| 28 | + |
| 29 | + constexpr auto k_timeout_seconds = 300; |
| 30 | ++ |
| 31 | ++#if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| 32 | ++static const char *thread_device_type_name(chip::DeviceLayer::ConnectivityManager::ThreadDeviceType device_type) |
| 33 | ++{ |
| 34 | ++ switch (device_type) { |
| 35 | ++ case chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_Router: |
| 36 | ++ return "router"; |
| 37 | ++ case chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_FullEndDevice: |
| 38 | ++ return "full end device"; |
| 39 | ++ default: |
| 40 | ++ return "other"; |
| 41 | ++ } |
| 42 | ++} |
| 43 | ++ |
| 44 | ++static void ensure_thread_device_type(chip::DeviceLayer::ConnectivityManager::ThreadDeviceType device_type, |
| 45 | ++ const char *reason) |
| 46 | ++{ |
| 47 | ++ auto &connectivity_mgr = chip::DeviceLayer::ConnectivityMgr(); |
| 48 | ++ |
| 49 | ++ if (connectivity_mgr.GetThreadDeviceType() == device_type) { |
| 50 | ++ ESP_LOGI(TAG, "Thread device type already %s for %s", thread_device_type_name(device_type), reason); |
| 51 | ++ return; |
| 52 | ++ } |
| 53 | ++ |
| 54 | ++ CHIP_ERROR err = connectivity_mgr.SetThreadDeviceType(device_type); |
| 55 | ++ if (err != CHIP_NO_ERROR) { |
| 56 | ++ ESP_LOGE(TAG, "Failed to set Thread device type to %s for %s: %" CHIP_ERROR_FORMAT, |
| 57 | ++ thread_device_type_name(device_type), reason, err.Format()); |
| 58 | ++ return; |
| 59 | ++ } |
| 60 | ++ |
| 61 | ++ ESP_LOGI(TAG, "Set Thread device type to %s for %s", thread_device_type_name(device_type), reason); |
| 62 | ++} |
| 63 | ++ |
| 64 | ++static bool is_uncommissioned() |
| 65 | ++{ |
| 66 | ++ return chip::Server::GetInstance().GetFabricTable().FabricCount() == 0; |
| 67 | ++} |
| 68 | ++#endif |
| 69 | + |
| 70 | + static const char *attribute_update_type_name(attribute::callback_type_t type) |
| 71 | + { |
| 72 | + switch (type) { |
| 73 | +@@ -130,6 +170,12 @@ |
| 74 | + |
| 75 | + case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted: |
| 76 | + ESP_LOGI(TAG, "Commissioning session started"); |
| 77 | ++#if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| 78 | ++ if (is_uncommissioned()) { |
| 79 | ++ ensure_thread_device_type(chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_FullEndDevice, |
| 80 | ++ "commissioning session"); |
| 81 | ++ } |
| 82 | ++#endif |
| 83 | + break; |
| 84 | + |
| 85 | + case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped: |
| 86 | +@@ -148,6 +194,10 @@ |
| 87 | + case chip::DeviceLayer::DeviceEventType::kFabricRemoved: { |
| 88 | + ESP_LOGI(TAG, "Fabric removed successfully"); |
| 89 | + if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) { |
| 90 | ++#if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| 91 | ++ ensure_thread_device_type(chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_FullEndDevice, |
| 92 | ++ "fabric removal"); |
| 93 | ++#endif |
| 94 | + chip::CommissioningWindowManager &commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager(); |
| 95 | + constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds); |
| 96 | + if (!commissionMgr.IsCommissioningWindowOpen()) { |
| 97 | +@@ -174,6 +224,9 @@ |
| 98 | + |
| 99 | + case chip::DeviceLayer::DeviceEventType::kFabricCommitted: |
| 100 | + ESP_LOGI(TAG, "Fabric is committed"); |
| 101 | ++#if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| 102 | ++ ensure_thread_device_type(chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_Router, "fabric commit"); |
| 103 | ++#endif |
| 104 | + break; |
| 105 | + |
| 106 | + case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized: |
| 107 | +@@ -294,6 +347,13 @@ |
| 108 | + err = esp_matter::start(app_event_cb); |
| 109 | + ABORT_APP_ON_FAILURE(err == ESP_OK, ESP_LOGE(TAG, "Failed to start Matter, err:%d", err)); |
| 110 | + |
| 111 | ++#if CHIP_DEVICE_CONFIG_ENABLE_THREAD |
| 112 | ++ if (is_uncommissioned()) { |
| 113 | ++ ensure_thread_device_type(chip::DeviceLayer::ConnectivityManager::kThreadDeviceType_FullEndDevice, |
| 114 | ++ "initial commissioning"); |
| 115 | ++ } |
| 116 | ++#endif |
| 117 | ++ |
| 118 | + MEMORY_PROFILER_DUMP_HEAP_STAT("matter started"); |
| 119 | + |
| 120 | + /* Starting driver with default values */ |
| 121 | +-- |
| 122 | +2.39.5 (Apple Git-154) |
0 commit comments