Skip to content

Commit c61703a

Browse files
committed
Adjustments to provision callback flows
1 parent 6bc7968 commit c61703a

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

examples/indicator_matter/main/model/indicator_matter.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static const char *TAG = "matter";
1919
uint16_t temperature_endpoint_id = 0;
2020
uint16_t humidity_endpoint_id = 0;
2121
uint16_t color_temperature_light_endpoint_id = 0;
22-
uint16_t door_lock_endpoint_id = 0;
22+
uint16_t on_off_light_endpoint_id = 0;
2323
uint16_t color_temperature_light_endpoint2_id = 0;
2424
static bool __g_matter_connected_flag = false;
2525
static bool __g_ip_connected_flag = false;
@@ -77,6 +77,11 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
7777
if (event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV6_Assigned ||
7878
event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned) {
7979
__g_ip_connected_flag = true;
80+
81+
struct view_data_wifi_st st;
82+
st.rssi = -50;
83+
st.is_connected = true;
84+
esp_event_post_to(view_event_handle, VIEW_EVENT_BASE, VIEW_EVENT_WIFI_ST, &st, sizeof(struct view_data_wifi_st ), portMAX_DELAY);
8085
}
8186
break;
8287
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: {
@@ -107,23 +112,23 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
107112
}
108113
case chip::DeviceLayer::DeviceEventType::kFabricRemoved:
109114
{
110-
ESP_LOGI(TAG, "Fabric removed successfully");
111-
__g_matter_connected_flag = false;
112-
chip::CommissioningWindowManager & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
113-
constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds);
114-
if (!commissionMgr.IsCommissioningWindowOpen())
115+
ESP_LOGI(TAG, "Fabric removed successfully");
116+
__g_matter_connected_flag = false;
117+
chip::CommissioningWindowManager & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
118+
constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds);
119+
if (!commissionMgr.IsCommissioningWindowOpen())
120+
{
121+
CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds,
122+
chip::CommissioningWindowAdvertisement::kDnssdOnly);
123+
if (err != CHIP_NO_ERROR)
115124
{
116-
CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds,
117-
chip::CommissioningWindowAdvertisement::kDnssdOnly);
118-
if (err != CHIP_NO_ERROR)
119-
{
120-
ESP_LOGE(TAG, "Failed to open commissioning window, err:%" CHIP_ERROR_FORMAT, err.Format());
121-
}
122-
123-
ESP_LOGI(TAG, "Beginning Matter Provisioning");
124-
uint8_t screen = SCREEN_MATTER_CONFIG;
125-
ESP_ERROR_CHECK(esp_event_post_to(view_event_handle, VIEW_EVENT_BASE, VIEW_EVENT_SCREEN_START, &screen, sizeof(screen), portMAX_DELAY));
125+
ESP_LOGE(TAG, "Failed to open commissioning window, err:%" CHIP_ERROR_FORMAT, err.Format());
126126
}
127+
}
128+
129+
ESP_LOGI(TAG, "Beginning Matter Provisioning");
130+
uint8_t screen = SCREEN_MATTER_CONFIG;
131+
ESP_ERROR_CHECK(esp_event_post_to(view_event_handle, VIEW_EVENT_BASE, VIEW_EVENT_SCREEN_START, &screen, sizeof(screen), portMAX_DELAY));
127132
break;
128133
}
129134
case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved:
@@ -135,19 +140,14 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
135140
break;
136141

137142
case chip::DeviceLayer::DeviceEventType::kFabricCommitted:
143+
{
138144
ESP_LOGI(TAG, "Fabric is committed");
139145

140146
__g_matter_connected_flag = true;
141-
if (__g_matter_connected_flag) {
142-
struct view_data_wifi_st st;
143-
st.rssi = -50;
144-
st.is_connected = true;
145-
esp_event_post_to(view_event_handle, VIEW_EVENT_BASE, VIEW_EVENT_WIFI_ST, &st, sizeof(struct view_data_wifi_st ), portMAX_DELAY);
146-
147-
uint8_t screen = SCREEN_DASHBOARD;
148-
ESP_ERROR_CHECK(esp_event_post_to(view_event_handle, VIEW_EVENT_BASE, VIEW_EVENT_SCREEN_START, &screen, sizeof(screen), portMAX_DELAY));
149-
}
147+
uint8_t screen = SCREEN_DASHBOARD;
148+
ESP_ERROR_CHECK(esp_event_post_to(view_event_handle, VIEW_EVENT_BASE, VIEW_EVENT_SCREEN_START, &screen, sizeof(screen), portMAX_DELAY));
150149
break;
150+
}
151151
default:
152152
break;
153153
}
@@ -203,9 +203,9 @@ static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16
203203
&data, sizeof(struct view_data_matter_dashboard_data ), portMAX_DELAY);
204204
}
205205
}
206-
} else if (endpoint_id == door_lock_endpoint_id) {
207-
if (cluster_id == DoorLock::Id) {
208-
if (attribute_id == DoorLock::Attributes::LockState::Id) {
206+
} else if (endpoint_id == on_off_light_endpoint_id) {
207+
if (cluster_id == OnOff::Id) {
208+
if (attribute_id == OnOff::Attributes::OnOff::Id) {
209209
struct view_data_matter_dashboard_data data;
210210
data.dashboard_data_type = DASHBOARD_DATA_SWITCH;
211211
data.value = (int)val->val.b;
@@ -221,7 +221,7 @@ static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16
221221
}
222222

223223
static void __matter_temperature_reporter(void* arg) {
224-
if (__g_matter_connected_flag && __g_ip_connected_flag) {
224+
if (__g_matter_connected_flag) {
225225
uint16_t endpoint_id = temperature_endpoint_id;
226226
uint32_t cluster_id = TemperatureMeasurement::Id;
227227
uint32_t attribute_id = TemperatureMeasurement::Attributes::MeasuredValue::Id;
@@ -243,7 +243,7 @@ static void __matter_temperature_reporter(void* arg) {
243243
}
244244

245245
static void __matter_humidity_reporter(void* arg) {
246-
if (__g_matter_connected_flag && __g_ip_connected_flag) {
246+
if (__g_matter_connected_flag) {
247247
uint16_t endpoint_id = humidity_endpoint_id;
248248
uint32_t cluster_id = RelativeHumidityMeasurement::Id;
249249
uint32_t attribute_id = RelativeHumidityMeasurement::Attributes::MeasuredValue::Id;
@@ -298,9 +298,9 @@ static void __view_event_handler(void* handler_args, esp_event_base_t base, int3
298298
break;
299299
}
300300
case DASHBOARD_DATA_SWITCH: {
301-
uint16_t endpoint_id = door_lock_endpoint_id;
302-
uint32_t cluster_id = DoorLock::Id;
303-
uint32_t attribute_id = DoorLock::Attributes::LockState::Id;
301+
uint16_t endpoint_id = on_off_light_endpoint_id;
302+
uint32_t cluster_id = OnOff::Id;
303+
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
304304
node_t *node = node::get();
305305
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
306306
cluster_t *cluster = cluster::get(endpoint, cluster_id);
@@ -407,7 +407,7 @@ static void __view_event_handler(void* handler_args, esp_event_base_t base, int3
407407

408408
int indicator_matter_setup(void) {
409409
esp_err_t err = ESP_OK;
410-
__g_matter_connected_flag = chip::DeviceLayer::Internal::ESP32Utils::IsStationProvisioned();
410+
__g_matter_connected_flag = chip::Server::GetInstance().GetFabricTable().FabricCount() > 0;
411411
__g_matter_mutex = xSemaphoreCreateMutex();
412412
node::config_t node_config;
413413
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
@@ -427,8 +427,8 @@ int indicator_matter_setup(void) {
427427
endpoint_t *color_temperature_light_endpoint = color_temperature_light::create(node, &color_temperature_light_config, ENDPOINT_FLAG_NONE, NULL);
428428

429429
// Create the contact sensor endpoint
430-
door_lock::config_t door_lock_config;
431-
endpoint_t *door_lock_endpoint = door_lock::create(node, &door_lock_config, ENDPOINT_FLAG_NONE, NULL);
430+
on_off_light::config_t on_off_light_config;
431+
endpoint_t *on_off_light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, NULL);
432432

433433
color_temperature_light::config_t color_temperature_light_config2;
434434
color_temperature_light_config2.level_control.lighting.min_level = 1;
@@ -439,7 +439,7 @@ int indicator_matter_setup(void) {
439439
!temperature_endpoint ||
440440
!humidity_endpoint ||
441441
!color_temperature_light_endpoint ||
442-
!door_lock_endpoint ||
442+
!on_off_light_endpoint ||
443443
!color_temperature_light_endpoint2
444444
) {
445445
ESP_LOGE(TAG, "Matter node creation failed");
@@ -454,8 +454,8 @@ int indicator_matter_setup(void) {
454454
color_temperature_light_endpoint_id = endpoint::get_id(color_temperature_light_endpoint);
455455
ESP_LOGI(TAG, "Dimmable light created with endpoint_id %d", color_temperature_light_endpoint_id);
456456

457-
door_lock_endpoint_id = endpoint::get_id(door_lock_endpoint);
458-
ESP_LOGI(TAG, "Door lock created with endpoint_id %d", door_lock_endpoint_id);
457+
on_off_light_endpoint_id = endpoint::get_id(on_off_light_endpoint);
458+
ESP_LOGI(TAG, "Door lock created with endpoint_id %d", on_off_light_endpoint_id);
459459

460460
color_temperature_light_endpoint2_id = endpoint::get_id(color_temperature_light_endpoint2);
461461
ESP_LOGI(TAG, "Dimmable plugin 2 unit created with endpoint_id %d", color_temperature_light_endpoint2_id);

examples/indicator_matter/sdkconfig.defaults

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL=y
143143
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
144144
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
145145
CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y
146-
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=256
146+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=1024
147147
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=0
148-
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
149148

150149
CONFIG_CHIP_PROJECT_CONFIG="main/matter_config.h"

0 commit comments

Comments
 (0)