@@ -19,7 +19,7 @@ static const char *TAG = "matter";
19
19
uint16_t temperature_endpoint_id = 0 ;
20
20
uint16_t humidity_endpoint_id = 0 ;
21
21
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 ;
23
23
uint16_t color_temperature_light_endpoint2_id = 0 ;
24
24
static bool __g_matter_connected_flag = false ;
25
25
static bool __g_ip_connected_flag = false ;
@@ -77,6 +77,11 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
77
77
if (event->InterfaceIpAddressChanged .Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV6_Assigned ||
78
78
event->InterfaceIpAddressChanged .Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned ) {
79
79
__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);
80
85
}
81
86
break ;
82
87
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete : {
@@ -107,23 +112,23 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
107
112
}
108
113
case chip::DeviceLayer::DeviceEventType::kFabricRemoved :
109
114
{
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)
115
124
{
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 ());
126
126
}
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));
127
132
break ;
128
133
}
129
134
case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved :
@@ -135,19 +140,14 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
135
140
break ;
136
141
137
142
case chip::DeviceLayer::DeviceEventType::kFabricCommitted :
143
+ {
138
144
ESP_LOGI (TAG, " Fabric is committed" );
139
145
140
146
__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));
150
149
break ;
150
+ }
151
151
default :
152
152
break ;
153
153
}
@@ -203,9 +203,9 @@ static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16
203
203
&data, sizeof (struct view_data_matter_dashboard_data ), portMAX_DELAY);
204
204
}
205
205
}
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) {
209
209
struct view_data_matter_dashboard_data data;
210
210
data.dashboard_data_type = DASHBOARD_DATA_SWITCH;
211
211
data.value = (int )val->val .b ;
@@ -221,7 +221,7 @@ static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16
221
221
}
222
222
223
223
static void __matter_temperature_reporter (void * arg) {
224
- if (__g_matter_connected_flag && __g_ip_connected_flag ) {
224
+ if (__g_matter_connected_flag) {
225
225
uint16_t endpoint_id = temperature_endpoint_id;
226
226
uint32_t cluster_id = TemperatureMeasurement::Id;
227
227
uint32_t attribute_id = TemperatureMeasurement::Attributes::MeasuredValue::Id;
@@ -243,7 +243,7 @@ static void __matter_temperature_reporter(void* arg) {
243
243
}
244
244
245
245
static void __matter_humidity_reporter (void * arg) {
246
- if (__g_matter_connected_flag && __g_ip_connected_flag ) {
246
+ if (__g_matter_connected_flag) {
247
247
uint16_t endpoint_id = humidity_endpoint_id;
248
248
uint32_t cluster_id = RelativeHumidityMeasurement::Id;
249
249
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
298
298
break ;
299
299
}
300
300
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;
304
304
node_t *node = node::get ();
305
305
endpoint_t *endpoint = endpoint::get (node, endpoint_id);
306
306
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
407
407
408
408
int indicator_matter_setup (void ) {
409
409
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 ;
411
411
__g_matter_mutex = xSemaphoreCreateMutex ();
412
412
node::config_t node_config;
413
413
node_t *node = node::create (&node_config, app_attribute_update_cb, app_identification_cb);
@@ -427,8 +427,8 @@ int indicator_matter_setup(void) {
427
427
endpoint_t *color_temperature_light_endpoint = color_temperature_light::create (node, &color_temperature_light_config, ENDPOINT_FLAG_NONE, NULL );
428
428
429
429
// 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 );
432
432
433
433
color_temperature_light::config_t color_temperature_light_config2;
434
434
color_temperature_light_config2.level_control .lighting .min_level = 1 ;
@@ -439,7 +439,7 @@ int indicator_matter_setup(void) {
439
439
!temperature_endpoint ||
440
440
!humidity_endpoint ||
441
441
!color_temperature_light_endpoint ||
442
- !door_lock_endpoint ||
442
+ !on_off_light_endpoint ||
443
443
!color_temperature_light_endpoint2
444
444
) {
445
445
ESP_LOGE (TAG, " Matter node creation failed" );
@@ -454,8 +454,8 @@ int indicator_matter_setup(void) {
454
454
color_temperature_light_endpoint_id = endpoint::get_id (color_temperature_light_endpoint);
455
455
ESP_LOGI (TAG, " Dimmable light created with endpoint_id %d" , color_temperature_light_endpoint_id);
456
456
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 );
459
459
460
460
color_temperature_light_endpoint2_id = endpoint::get_id (color_temperature_light_endpoint2);
461
461
ESP_LOGI (TAG, " Dimmable plugin 2 unit created with endpoint_id %d" , color_temperature_light_endpoint2_id);
0 commit comments