Matter 이산화탄소 농도 측정 센서 예제 프로젝트
다음 Matter 클러스터들에 대한 코드 구현 방법을 알아본다
- Carbon Dioxide Concentration Measurement (Cluster Id:
0x040D
) - Temperature Measurement (Cluster ID:
0x0402
) - Relative Humidity Measurement (Cluster ID:
0x0405
)
2024년 2월 18일 기준 Apple Home 및 Google Home 모두 Air Quality Device Type 지원하지 않음
1개의 Endpoint가 아래와 같이 생성된다. (센서 모듈이 CO2 농도 뿐만 아니라 온도와 상대 습도 데이터도 제공함)
- Endpoint ID
1
Device Type: Air Quality Sensor (Classification ID:0x002C
)
[Clusters]- Air Quality (Cluster ID:
0x005B
) - Carbon Dioxide Concentration Measurement (Cluster ID:
0x040D
)
[Attributes]- Measured Value (Attribute ID:
0x0000
) - Min Measured Value (Attribute ID:
0x0001
) - Max Measured Value (Attribute ID:
0x0002
) - Measurement Unit (Attribute ID:
0x0008
)
- Measured Value (Attribute ID:
- Temperature Measurement (Cluster ID:
0x0402
)
[Attributes]- Measured Value (Attribute ID:
0x0000
) - Min Measured Value (Attribute ID:
0x0001
) - Max Measured Value (Attribute ID:
0x0002
)
- Measured Value (Attribute ID:
- Relative Humidity Measurement (Cluster ID:
0x0405
)
[Attributes]- Measured Value (Attribute ID:
0x0000
) - Min Measured Value (Attribute ID:
0x0001
) - Max Measured Value (Attribute ID:
0x0002
)
- Measured Value (Attribute ID:
- Air Quality (Cluster ID:
SCD41: I2C 통신 방식의 CO2 센서 IC 사용
I2C GPIO 핀번호 변경은 /main/include/definition.h에서 아래 항목을 수정
default: SDA
= GPIO18
/ SCL
= GPIO19
#define GPIO_PIN_I2C_SCL 19
#define GPIO_PIN_I2C_SDA 18
- esp-idf: v5.1.2
- esp-matter: fe4f9f69634b060744f06560b7afdaf25d96ba37
- connectedhomeip: d38a6496c3abeb3daf6429b1f11172cfa0112a1a
- Matter 1.1 released (2023.05.18)
- Matter 1.2 released (2023.10.23)
- esp_matter_cluster.h
namespace carbon_dioxide_concentration_measurement { typedef struct config { uint16_t cluster_revision; config() : cluster_revision(3) {} } config_t; // 아래 한줄 추가 cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* carbon_dioxide_concentration_measurement */
- esp_matter_attribute.cpp
static esp_err_t get_attr_val_from_data(esp_matter_attr_val_t *val, EmberAfAttributeType attribute_type, uint16_t attribute_size, uint8_t *value, const EmberAfAttributeMetadata * attribute_metadata) { switch (attribute_type) { /* * 기존 코드 유지 */ // 아래 블록 추가 case ZCL_SINGLE_ATTRIBUTE_TYPE: { using Traits = chip::app::NumericAttributeTraits<float>; Traits::StorageType attribute_value; memcpy((float *)&attribute_value, value, sizeof(Traits::StorageType)); if (attribute_metadata->IsNullable()) { if (Traits::IsNullValue(attribute_value)) { *val = esp_matter_nullable_float(nullable<float>()); } else { *val = esp_matter_nullable_float(attribute_value); } } else { *val = esp_matter_float(attribute_value); } break; } default: *val = esp_matter_invalid(NULL); break; } return ESP_OK; }
SDK 클론 및 설치
$ source ./scripts/install_sdk.sh
SDK (idf.py) 준비
$ source ./scripts/prepare_sdk.sh
- Factory Partition (Matter DAC)
$ source ./scripts/flash_factory_dac_provider.sh
- Configure project
$ idf.py set-target esp32
- Build Firmware
$ idf.py build
- Flash Firmware
$ idf.py -p ${seiral_port} flash monitor
이산화탄소 농도 측정값 읽기
$ chip-tool carbondioxideconcentrationmeasurement read measured-value {pairing_node_id} 1
온도 측정값 읽기
$ chip-tool temperaturemeasurement read measured-value {pairing_node_id} 1
습도 측정값 읽기
$ chip-tool relativehumiditymeasurement read measured-value {pairing_node_id} 1