mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
57c55bd711
Update Cluster Revision of all clusters Add scene clusters missing commands Add Product Appearance attribute to basic information cluster Add missing attributes in color control cluster Add breadcrumb attribute Add missing attributes and commands in bridged device information cluster Fix typo in basic information cluster Add Scene Table Size attribute Fix CI for zigbee bridge Add attribute bounds and string length checks
118 lines
3.5 KiB
C++
118 lines
3.5 KiB
C++
/*
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
|
|
#include <esp_err.h>
|
|
#include <esp_log.h>
|
|
#include <nvs_flash.h>
|
|
|
|
#include <esp_matter.h>
|
|
#include <esp_matter_console.h>
|
|
#include <esp_matter_ota.h>
|
|
|
|
#include <app_bridged_device.h>
|
|
#include <app_zboss.h>
|
|
#include <zigbee_bridge.h>
|
|
|
|
static const char *TAG = "app_main";
|
|
|
|
using namespace esp_matter;
|
|
using namespace esp_matter::attribute;
|
|
using namespace esp_matter::endpoint;
|
|
|
|
uint16_t aggregator_endpoint_id = chip::kInvalidEndpointId;
|
|
|
|
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
|
|
{
|
|
switch (event->Type) {
|
|
case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged:
|
|
ESP_LOGI(TAG, "Interface IP Address Changed");
|
|
break;
|
|
|
|
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete:
|
|
ESP_LOGI(TAG, "Commissioning complete");
|
|
break;
|
|
|
|
case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired:
|
|
ESP_LOGI(TAG, "Commissioning failed, fail safe timer expired");
|
|
break;
|
|
|
|
case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted:
|
|
ESP_LOGI(TAG, "Commissioning session started");
|
|
break;
|
|
|
|
case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped:
|
|
ESP_LOGI(TAG, "Commissioning session stopped");
|
|
break;
|
|
|
|
case chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened:
|
|
ESP_LOGI(TAG, "Commissioning window opened");
|
|
break;
|
|
|
|
case chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed:
|
|
ESP_LOGI(TAG, "Commissioning window closed");
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static esp_err_t app_attribute_update_cb(callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id,
|
|
uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data)
|
|
{
|
|
esp_err_t err = ESP_OK;
|
|
|
|
if (type == PRE_UPDATE) {
|
|
err = zigbee_bridge_attribute_update(endpoint_id, cluster_id, attribute_id, val, (app_bridged_device_t *)priv_data);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
extern "C" void app_main()
|
|
{
|
|
esp_err_t err = ESP_OK;
|
|
|
|
/* Initialize the ESP NVS layer */
|
|
nvs_flash_init();
|
|
|
|
/* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */
|
|
node::config_t node_config;
|
|
node_t *node = node::create(&node_config, app_attribute_update_cb, NULL);
|
|
|
|
/* These node and endpoint handles can be used to create/add other endpoints and clusters. */
|
|
if (!node) {
|
|
ESP_LOGE(TAG, "Matter node creation failed");
|
|
}
|
|
|
|
aggregator::config_t aggregator_config;
|
|
endpoint_t *aggregator = endpoint::aggregator::create(node, &aggregator_config, ENDPOINT_FLAG_NONE, NULL);
|
|
if (!aggregator) {
|
|
ESP_LOGE(TAG, "Matter aggregator endpoint creation failed");
|
|
} else {
|
|
aggregator_endpoint_id = endpoint::get_id(aggregator);
|
|
}
|
|
|
|
/* Matter start */
|
|
err = esp_matter::start(app_event_cb);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "Matter start failed: %d", err);
|
|
}
|
|
|
|
err = app_bridge_initialize(node);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "Failed to resume the bridged endpoints: %d", err);
|
|
}
|
|
|
|
#if CONFIG_ENABLE_CHIP_SHELL
|
|
esp_matter::console::diagnostics_register_commands();
|
|
esp_matter::console::wifi_register_commands();
|
|
esp_matter::console::init();
|
|
#endif
|
|
launch_app_zboss();
|
|
}
|