指南ESP-Matter开发指南:精彩无限
1. 开发环境设置
1.1 主机设置
注: esp-matter底层已经依赖CSA matter官方仓库相关版本,用户设备层只需按照需求安装相关依赖工具
1.1 仓库获取
IDF仓库获取设置
git clone --recursive https://github.com/espressif/esp-idf.git //获取IDF相关仓库
cd esp-idf
git checkout release/v4.4 //切换对应分支
git submodule update --init --recursive //更新子组件依赖,此处可能需要很长时间
./install.sh //安装相应的依赖工具
cd ..
Matter仓库获取设置
git clone --recursive https://github.com/espressif/esp-matter.git
cd esp-matter
./install.sh
cd ..
1.2 环境变量配置
每次打开新的终端时执行如下操作
cd esp-idf
. ./export.sh //配置idf环境变量
cd esp-matter
. ./export.sh; //配置matter环境变量
1.3 相关配置界面如下
idf配置成功界面
esp-matter配置界面
配置成功界面
设备日志界面
2. 调试控制
2.1 调试
基于主机的芯片工具可以用作调试器来调试和控制 Matter 设备。
chip-tool pairing ble-wifi 0x7283 <ssid> <passphrase> 20202021 3840
在上述命令中:
0x7283
是随机选择的node_id
20202021
是个setup_passcode
3840
是个discriminator

基于esp-matter/connectedhomeip/connectedhomeip 打包的APP进行调试
打包路径界面如下:
2.2 控制
相关控制界面日志如下:
3. 功能逻辑梳理
以esp-matter标准数据模型色温灯为例:
3.1 数据endpoint
/cluster
定义
3.2 数据cluster
/attribute
、feature
定义
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
{
cluster_t *cluster = cluster::create(endpoint, ColorControl::Id, flags);
if (!cluster) {
ESP_LOGE(TAG, "Could not create cluster");
return NULL;
}
if (flags & CLUSTER_FLAG_SERVER) {
set_plugin_server_init_callback(cluster, MatterColorControlPluginServerInitCallback);
add_function_list(cluster, function_list, function_flags);
}
if (flags & CLUSTER_FLAG_CLIENT) {
set_plugin_client_init_callback(cluster, MatterColorControlPluginClientInitCallback);
create_default_binding_cluster(endpoint);
}
if (flags & CLUSTER_FLAG_SERVER) {
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, 0);
/* Attributes not managed internally */
if (config) {
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
attribute::create_color_mode(cluster, config->color_mode);
attribute::create_color_control_options(cluster, config->color_control_options);
attribute::create_enhanced_color_mode(cluster, config->enhanced_color_mode);
attribute::create_color_capabilities(cluster, config->color_capabilities);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
/* Attributes managed internally */
attribute::create_remaining_time(cluster, 0);
}
/* Features */
if (features & feature::hue_saturation::get_id()) {
feature::hue_saturation::add(cluster, &(config->hue_saturation));
}
if (features & feature::color_temperature::get_id()) {
feature::color_temperature::add(cluster, &(config->color_temperature));
}
if (features & feature::xy::get_id()) {
feature::xy::add(cluster, &(config->xy));
}
if (features & feature::enhanced_hue::get_id()) {
feature::enhanced_hue::add(cluster, &(config->enhanced_hue));
}
if (features & feature::color_loop::get_id()) {
feature::color_loop::add(cluster, &(config->color_loop));
}
return cluster;
}
} /* color_control */
3.3 attribute
、feature
/command
数据定义
参考链接:[https://docs.espressif.com/projects/esp-matter/en/main/esp32/developing.html]