Initial commit

This commit is contained in:
2026-03-31 13:17:21 +02:00
commit 7eeecff042
6821 changed files with 3514215 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
#include "Matter.h"
#include <app/server/OnboardingCodesUtil.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
using namespace chip;
using namespace chip::app::Clusters;
using namespace esp_matter;
using namespace esp_matter::endpoint;
/**
This program presents many Matter devices and should be used only
for debug purposes (for example checking which devices types are supported
in Matter controller).
Keep in mind that it IS NOT POSSIBLE to run all those endpoints due to
out of memory. There is need to manually comment out endpoints!
Running about 4 endpoints at the same time should work.
*/
static void on_device_event(const ChipDeviceEvent *event, intptr_t arg) {}
static esp_err_t on_identification(identification::callback_type_t type, uint16_t endpoint_id,
uint8_t effect_id, uint8_t effect_variant, void *priv_data) {
return ESP_OK;
}
static esp_err_t on_attribute_update(attribute::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) {
if (type == attribute::PRE_UPDATE) {
Serial.print("Update on endpoint: ");
Serial.print(endpoint_id);
Serial.print(" cluster: ");
Serial.print(cluster_id);
Serial.print(" attribute: ");
Serial.println(attribute_id);
}
return ESP_OK;
}
void print_endpoint_info(String clusterName, endpoint_t *endpoint) {
uint16_t endpoint_id = endpoint::get_id(endpoint);
Serial.print(clusterName);
Serial.print(" has endpoint: ");
Serial.println(endpoint_id);
}
void setup() {
Serial.begin(115200);
esp_log_level_set("*", ESP_LOG_DEBUG);
node::config_t node_config;
node_t *node = node::create(&node_config, on_attribute_update, on_identification);
endpoint_t *endpoint;
cluster_t *cluster;
// !!!
// USE ONLY ABOUT 4 ENDPOINTS TO AVOID OUT OF MEMORY ERRORS
// MANUALLY COMMENT REST OF ENDPOINTS
// !!!
on_off_light::config_t light_config;
endpoint = on_off_light::create(node, &light_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("on_off_light", endpoint);
dimmable_light::config_t dimmable_light_config;
endpoint = dimmable_light::create(node, &dimmable_light_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("dimmable_light", endpoint);
color_temperature_light::config_t color_temperature_light_config;
endpoint = color_temperature_light::create(node, &color_temperature_light_config, ENDPOINT_FLAG_NONE, NULL);
/* Add color control cluster */
cluster = cluster::get(endpoint, ColorControl::Id);
cluster::color_control::feature::hue_saturation::config_t hue_saturation_config;
cluster::color_control::feature::hue_saturation::add(cluster, &hue_saturation_config);
print_endpoint_info("color_temperature_light", endpoint);
extended_color_light::config_t extended_color_light_config;
endpoint = extended_color_light::create(node, &extended_color_light_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("extended_color_light", endpoint);
generic_switch::config_t generic_switch_config;
generic_switch_config.switch_cluster.current_position = 1;
generic_switch_config.switch_cluster.number_of_positions = 3;
endpoint = generic_switch::create(node, &generic_switch_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("generic_switch", endpoint);
on_off_plugin_unit::config_t on_off_plugin_unit_config;
on_off_plugin_unit_config.on_off.on_off = true;
endpoint = on_off_plugin_unit::create(node, &on_off_plugin_unit_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("on_off_plugin_unit", endpoint);
dimmable_plugin_unit::config_t dimmable_plugin_unit_config;
endpoint = dimmable_plugin_unit::create(node, &dimmable_plugin_unit_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("dimmable_plugin_unit", endpoint);
fan::config_t fan_config;
endpoint = fan::create(node, &fan_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("fan", endpoint);
thermostat::config_t thermostat_config;
thermostat_config.thermostat.local_temperature = 19;
endpoint = thermostat::create(node, &thermostat_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("thermostat", endpoint);
door_lock::config_t door_lock_config;
door_lock_config.door_lock.lock_state = 1;
endpoint = door_lock::create(node, &door_lock_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("door_lock", endpoint);
window_covering_device::config_t window_covering_device_config;
endpoint = window_covering_device::create(node, &window_covering_device_config, ENDPOINT_FLAG_NONE, NULL);
/* Add additional control clusters */
cluster = cluster::get(endpoint, WindowCovering::Id);
cluster::window_covering::feature::lift::config_t lift;
cluster::window_covering::feature::tilt::config_t tilt;
cluster::window_covering::feature::position_aware_lift::config_t position_aware_lift;
cluster::window_covering::feature::position_aware_tilt::config_t position_aware_tilt;
cluster::window_covering::feature::absolute_position::config_t absolute_position;
cluster::window_covering::feature::lift::add(cluster, &lift);
cluster::window_covering::feature::tilt::add(cluster, &tilt);
cluster::window_covering::feature::position_aware_lift::add(cluster, &position_aware_lift);
cluster::window_covering::feature::position_aware_tilt::add(cluster, &position_aware_tilt);
cluster::window_covering::feature::absolute_position::add(cluster, &absolute_position);
print_endpoint_info("window_covering_device", endpoint);
temperature_sensor::config_t temperature_sensor_config;
temperature_sensor_config.temperature_measurement.measured_value = 22;
endpoint = temperature_sensor::create(node, &temperature_sensor_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("temperature_sensor", endpoint);
occupancy_sensor::config_t occupancy_sensor_config;
occupancy_sensor_config.occupancy_sensing.occupancy = 1;
endpoint = occupancy_sensor::create(node, &occupancy_sensor_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("occupancy_sensor", endpoint);
contact_sensor::config_t contact_sensor_config;
contact_sensor_config.boolean_state.state_value = true;
endpoint = contact_sensor::create(node, &contact_sensor_config, ENDPOINT_FLAG_NONE, NULL);
print_endpoint_info("contact_sensor", endpoint);
// Setup DAC (this is good place to also set custom commission data, passcodes etc.)
esp_matter::set_custom_dac_provider(chip::Credentials::Examples::GetExampleDACProvider());
esp_matter::start(on_device_event);
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}
void loop() {
}

View File

@@ -0,0 +1,116 @@
#include "Matter.h"
#include <app/server/OnboardingCodesUtil.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
using namespace chip;
using namespace chip::app::Clusters;
using namespace esp_matter;
using namespace esp_matter::endpoint;
/**
* This program presents example Matter light device with OnOff cluster by
* controlling LED with Matter and toggle button.
*
* If your ESP does not have buildin LED, please connect it to LED_PIN
*
* You can toggle light by both:
* - Matter (via CHIPTool or other Matter controller)
* - toggle button (by default attached to GPIO0 - reset button, with debouncing)
*/
// Please configure your PINs
const int LED_PIN = 2;
const int TOGGLE_BUTTON_PIN = 0;
// Debounce for toggle button
const int DEBOUNCE_DELAY = 500;
int last_toggle;
// Cluster and attribute ID used by Matter light device
const uint32_t CLUSTER_ID = OnOff::Id;
const uint32_t ATTRIBUTE_ID = OnOff::Attributes::OnOff::Id;
// Endpoint and attribute ref that will be assigned to Matter device
uint16_t light_endpoint_id = 0;
attribute_t *attribute_ref;
// There is possibility to listen for various device events, related for example to setup process
// Leaved as empty for simplicity
static void on_device_event(const ChipDeviceEvent *event, intptr_t arg) {}
static esp_err_t on_identification(identification::callback_type_t type, uint16_t endpoint_id,
uint8_t effect_id, uint8_t effect_variant, void *priv_data) {
return ESP_OK;
}
// Listener on attribute update requests.
// In this example, when update is requested, path (endpoint, cluster and attribute) is checked
// if it matches light attribute. If yes, LED changes state to new one.
static esp_err_t on_attribute_update(attribute::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) {
if (type == attribute::PRE_UPDATE && endpoint_id == light_endpoint_id &&
cluster_id == CLUSTER_ID && attribute_id == ATTRIBUTE_ID) {
// We got an light on/off attribute update!
bool new_state = val->val.b;
digitalWrite(LED_PIN, new_state);
}
return ESP_OK;
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(TOGGLE_BUTTON_PIN, INPUT);
// Enable debug logging
esp_log_level_set("*", ESP_LOG_DEBUG);
// Setup Matter node
node::config_t node_config;
node_t *node = node::create(&node_config, on_attribute_update, on_identification);
// Setup Light endpoint / cluster / attributes with default values
on_off_light::config_t light_config;
light_config.on_off.on_off = false;
light_config.on_off.lighting.start_up_on_off = false;
endpoint_t *endpoint = on_off_light::create(node, &light_config, ENDPOINT_FLAG_NONE, NULL);
// Save on/off attribute reference. It will be used to read attribute value later.
attribute_ref = attribute::get(cluster::get(endpoint, CLUSTER_ID), ATTRIBUTE_ID);
// Save generated endpoint id
light_endpoint_id = endpoint::get_id(endpoint);
// Setup DAC (this is good place to also set custom commission data, passcodes etc.)
esp_matter::set_custom_dac_provider(chip::Credentials::Examples::GetExampleDACProvider());
// Start Matter device
esp_matter::start(on_device_event);
// Print codes needed to setup Matter device
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}
// Reads light on/off attribute value
esp_matter_attr_val_t get_onoff_attribute_value() {
esp_matter_attr_val_t onoff_value = esp_matter_invalid(NULL);
attribute::get_val(attribute_ref, &onoff_value);
return onoff_value;
}
// Sets light on/off attribute value
void set_onoff_attribute_value(esp_matter_attr_val_t* onoff_value) {
attribute::update(light_endpoint_id, CLUSTER_ID, ATTRIBUTE_ID, onoff_value);
}
// When toggle light button is pressed (with debouncing),
// light attribute value is changed
void loop() {
if ((millis() - last_toggle) > DEBOUNCE_DELAY) {
if (!digitalRead(TOGGLE_BUTTON_PIN)) {
last_toggle = millis();
// Read actual on/off value, invert it and set
esp_matter_attr_val_t onoff_value = get_onoff_attribute_value();
onoff_value.val.b = !onoff_value.val.b;
set_onoff_attribute_value(&onoff_value);
}
}
}

View File

@@ -0,0 +1,145 @@
#include "Matter.h"
#include <app/server/OnboardingCodesUtil.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
using namespace chip;
using namespace chip::app::Clusters;
using namespace esp_matter;
using namespace esp_matter::endpoint;
/**
* This program presents example Matter plugin unit (switch) device with two endpoints
* with OnOff clusters by controlling LEDs with Matter and toggle buttons.
*
* You can toggle plugin unit by both:
* - Matter (via CHIPTool or other Matter controller)
* - toggle button (with debouncing)
*/
// Please configure your PINs
const int LED_PIN_1 = 2;
const int LED_PIN_2 = 17;
const int TOGGLE_BUTTON_PIN_1 = 0;
const int TOGGLE_BUTTON_PIN_2 = 21;
// Debounce for toggle button
const int DEBOUNCE_DELAY = 500;
int last_toggle;
// Cluster and attribute ID used by Matter plugin unit device
const uint32_t CLUSTER_ID = OnOff::Id;
const uint32_t ATTRIBUTE_ID = OnOff::Attributes::OnOff::Id;
// Endpoint and attribute ref that will be assigned to Matter device
uint16_t plugin_unit_endpoint_id_1 = 0;
uint16_t plugin_unit_endpoint_id_2 = 0;
attribute_t *attribute_ref_1;
attribute_t *attribute_ref_2;
// There is possibility to listen for various device events, related for example
// to setup process. Leaved as empty for simplicity.
static void on_device_event(const ChipDeviceEvent *event, intptr_t arg) {}
static esp_err_t on_identification(identification::callback_type_t type,
uint16_t endpoint_id, uint8_t effect_id,
uint8_t effect_variant, void *priv_data) {
return ESP_OK;
}
// Listener on attribute update requests.
// In this example, when update is requested, path (endpoint, cluster and
// attribute) is checked if it matches plugin unit attribute. If yes, LED changes
// state to new one.
static esp_err_t on_attribute_update(attribute::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) {
if (type == attribute::PRE_UPDATE && cluster_id == CLUSTER_ID && attribute_id == ATTRIBUTE_ID) {
// We got an plugin unit on/off attribute update!
bool new_state = val->val.b;
if (endpoint_id == plugin_unit_endpoint_id_1) {
digitalWrite(LED_PIN_1, new_state);
} else if (endpoint_id == plugin_unit_endpoint_id_2) {
digitalWrite(LED_PIN_2, new_state);
}
}
return ESP_OK;
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN_1, OUTPUT);
pinMode(LED_PIN_2, OUTPUT);
pinMode(TOGGLE_BUTTON_PIN_1, INPUT);
pinMode(TOGGLE_BUTTON_PIN_2, INPUT);
// Enable debug logging
esp_log_level_set("*", ESP_LOG_DEBUG);
// Setup Matter node
node::config_t node_config;
node_t *node =
node::create(&node_config, on_attribute_update, on_identification);
// Setup Plugin unit endpoint / cluster / attributes with default values
on_off_plugin_unit::config_t plugin_unit_config;
plugin_unit_config.on_off.on_off = false;
plugin_unit_config.on_off.lighting.start_up_on_off = false;
endpoint_t *endpoint_1 = on_off_plugin_unit::create(node, &plugin_unit_config,
ENDPOINT_FLAG_NONE, NULL);
endpoint_t *endpoint_2 = on_off_plugin_unit::create(node, &plugin_unit_config,
ENDPOINT_FLAG_NONE, NULL);
// Save on/off attribute reference. It will be used to read attribute value later.
attribute_ref_1 =
attribute::get(cluster::get(endpoint_1, CLUSTER_ID), ATTRIBUTE_ID);
attribute_ref_2 =
attribute::get(cluster::get(endpoint_2, CLUSTER_ID), ATTRIBUTE_ID);
// Save generated endpoint id
plugin_unit_endpoint_id_1 = endpoint::get_id(endpoint_1);
plugin_unit_endpoint_id_2 = endpoint::get_id(endpoint_2);
// Setup DAC (this is good place to also set custom commission data, passcodes etc.)
esp_matter::set_custom_dac_provider(chip::Credentials::Examples::GetExampleDACProvider());
// Start Matter device
esp_matter::start(on_device_event);
// Print codes needed to setup Matter device
PrintOnboardingCodes(
chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
}
// Reads plugin unit on/off attribute value
esp_matter_attr_val_t get_onoff_attribute_value(esp_matter::attribute_t *attribute_ref) {
esp_matter_attr_val_t onoff_value = esp_matter_invalid(NULL);
attribute::get_val(attribute_ref, &onoff_value);
return onoff_value;
}
// Sets plugin unit on/off attribute value
void set_onoff_attribute_value(esp_matter_attr_val_t *onoff_value, uint16_t plugin_unit_endpoint_id) {
attribute::update(plugin_unit_endpoint_id, CLUSTER_ID, ATTRIBUTE_ID, onoff_value);
}
// When toggle plugin unit button is pressed (with debouncing),
// plugin unit attribute value is changed
void loop() {
if ((millis() - last_toggle) > DEBOUNCE_DELAY) {
if (!digitalRead(TOGGLE_BUTTON_PIN_1)) {
last_toggle = millis();
// Read actual on/off value, invert it and set
esp_matter_attr_val_t onoff_value = get_onoff_attribute_value(attribute_ref_1);
onoff_value.val.b = !onoff_value.val.b;
set_onoff_attribute_value(&onoff_value, plugin_unit_endpoint_id_1);
}
if (!digitalRead(TOGGLE_BUTTON_PIN_2)) {
last_toggle = millis();
// Read actual on/off value, invert it and set
esp_matter_attr_val_t onoff_value = get_onoff_attribute_value(attribute_ref_2);
onoff_value.val.b = !onoff_value.val.b;
set_onoff_attribute_value(&onoff_value, plugin_unit_endpoint_id_2);
}
}
}