Open JoseAntonioMG opened 3 weeks ago
Could you please try to add an error check at esp_matter::attribute::update
? So that we can debug what is the issue. Please use the attribute::get_val
API instead of voltaje_value.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT16;
before updating the attribute to get the correct attribute type because the attribute type of the Voltage
attribute is int64.
Please try the above suggestion so that we get clear understanding of the issue.
@JoseAntonioMG In your code, you have created a PowerSource
device type and are updating the attribute of the ElectricalPowerMeasurement
Cluster.
esp_matter::attribute::update does not produce an error, I have changed the type esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT16 to esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64, however I still have the same problem.
I have also tried the following device types:
electrical_sensor
electrical_sensor::config_t electrical_sensor_config;
endpoint_t *energy_sensor_endpoint = electrical_sensor::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, energy_sensor_handle);
if (energy_sensor_endpoint)
{
energy_sensor_endpoint_id = endpoint::get_id(energy_sensor_endpoint);
ESP_LOGI(TAG, "Power Device PZEM004T. Endpoint: %d", energy_sensor_endpoint_id);
}
electrical_power_measurement
cluster::electrical_power_measurement::config_t electrical_sensor_config;
endpoint_t *energy_sensor_endpoint = cluster::electrical_power_measurement::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, energy_sensor_handle);
if (energy_sensor_endpoint)
{
energy_sensor_endpoint_id = endpoint::get_id(energy_sensor_endpoint);
ESP_LOGI(TAG, "Power Device PZEM004T. Endpoint: %d", energy_sensor_endpoint_id);
}
device_energy_management
device_energy_management::config_t electrical_sensor_config;
endpoint_t *energy_sensor_endpoint = device_energy_management::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, energy_sensor_handle);
if (energy_sensor_endpoint)
{
energy_sensor_endpoint_id = endpoint::get_id(energy_sensor_endpoint);
ESP_LOGI(TAG, "Power Device PZEM004T. Endpoint: %d", energy_sensor_endpoint_id);
}
and none of them work properly. Also, I have compiled and flashed the All_devices_types_app example, and created the electrical_power_measurement device, which is listed in the list of available devices, however it does not solve the problem.
I have the feeling that the devices for power measurements of different devices are not implemented correctly.
@JoseAntonioMG Did you create the Voltage
attribute on the electrical_power_measurement
cluster? Since Voltage is an optional attribute in Matter Spec, ESP-Matter doesn’t create it by default. You have to create it in your application explicitly before updating it. Please take a look at esp-matter-components for better understanding.
Does this mean I need to create the optional attributes for the Matter SDK? How can I create the voltage attribute?
It is possible to construct the attribute in this way:
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
if (node!=nullptr)
{
on_off_light::config_t on_off_light_config;
endpoint_t *light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, light_handle);
if (light_endpoint)
{
light_endpoint_id = endpoint::get_id(light_endpoint);
ESP_LOGI(TAG, "Light. Endpoint: %d", light_endpoint_id);
}
device_energy_management::config_t electrical_sensor_config;
esp_matter::cluster_t *energy_cluster = device_energy_management::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, energy_sensor_handle);
energy_sensor_endpoint_id = endpoint::get_id(energy_cluster);
esp_matter_attr_val_t voltaje_value;
voltaje_value = esp_matter_invalid(NULL);
voltaje_value.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
esp_matter::attribute::create(energy_cluster, ElectricalPowerMeasurement::Attributes::Voltage::Id, ATTRIBUTE_FLAG_NONE, voltaje_value);
ESP_LOGI(TAG, "Power Device PZEM004T. Endpoint: %d", energy_sensor_endpoint_id);
esp_openthread_platform_config_t config = {.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),};
set_openthread_platform_config(&config);
err = esp_matter::start(app_event_cb);
if(err==ESP_OK)
{
esp_matter::console::diagnostics_register_commands();
esp_matter::console::init();
}
else
{
ESP_LOGE(TAG, "Fallo en el arranque de Matter, err:%d", err);
}
}
Please go through the docs of create your own data model.
I have created a new Voltage attribute and it works:
electrical_power_measurement::config_t electrical_sensor_config;
esp_matter::cluster_t *energy_cluster = electrical_power_measurement::create(main_endpoint, &electrical_sensor_config, CLUSTER_FLAG_SERVER, electrical_power_measurement::feature::direct_current::get_id() | electrical_power_measurement::feature::alternating_current::get_id());
int64_t Voltaje = 0;
electrical_power_measurement::attribute::create_voltage(energy_cluster, Voltaje);
However, I need to create the "electrical power measurement" cluster on a new endpoint, independent of "main_endpoint", where I have other clusters. In this example:
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
on_off_light::config_t on_off_light_config;
endpoint_t *light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, light_handle);
light_endpoint_id = endpoint::get_id(light_endpoint);
electrical_power_measurement::config_t electrical_sensor_config;
esp_matter::cluster_t *energy_cluster = electrical_power_measurement::create(node, &electrical_sensor_config, CLUSTER_FLAG_SERVER, electrical_power_measurement::feature::direct_current::get_id() | electrical_power_measurement::feature::alternating_current::get_id());
energy_endpoint_id = endpoint::get_id(energy_cluster);
int64_t Voltaje = 0;
cluster::electrical_power_measurement::attribute::create_voltage(energy_cluster, Voltaje);
"node" is the main node from which all the clusters hang. In the electrical_power_measurement::create method I cannot specify a handler for the energy_cluster cluster, as I have been able to specify in the on_off_light cluster. This example not work.
I have created another example for a temperature sensor:
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
on_off_light::config_t on_off_light_config;
endpoint_t *light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, light_handle);
light_endpoint_id = endpoint::get_id(light_endpoint);
temperature_sensor::config_t temperature_sensor_config;
endpoint_t *temperature_sensor_endpoint = temperature_sensor::create(node, &temperature_sensor_config, ENDPOINT_FLAG_NONE, temperature_sensor_handle);
temperature_sensor_endpoint_id = endpoint::get_id(temperature_sensor_endpoint);
This example does work
In the electrical_power_measurement::create method I cannot specify a handler for the energy_cluster cluster, as I have been able to specify in the on_off_light cluster. This example not work.
The handler can be set to an endpoint and not the cluster. So please create ElectricalSensor
device type and create electrical_power_measurement
cluster on same endpoint.
@jadhavrohit924 I have created the "ElectricalSensor" endpoint and I have also created the "electrical_power_measurement" cluster, to which I have assigned the endpoint corresponding to ElectricalSensor, but the log shows that the cluster and also the attributes already exist, and therefore they are not created.
extern "C" void app_main()
{
esp_err_t err = ESP_OK;
nvs_flash_init();
app_driver_handle_t electrical_sensor_handle = app_driver_PZEM004T_sensor_init();
app_driver_handle_t light_handle = app_driver_light_init();
app_driver_handle_t button_handle = app_driver_button_init();
app_reset_button_register(button_handle);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
if (node!=nullptr)
{
on_off_light::config_t on_off_light_config;
endpoint_t *light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, light_handle);
if (light_endpoint)
{
light_endpoint_id = endpoint::get_id(light_endpoint);
ESP_LOGI(TAG, "Light Endpoint: %d", light_endpoint_id);
}
electrical_sensor::config_t electrical_sensor_config;
endpoint_t *electrical_endpoint = electrical_sensor::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, electrical_sensor_handle);
if (electrical_endpoint)
{
electrical_endpoint_id = endpoint::get_id(electrical_endpoint);
ESP_LOGI(TAG, "Electrical Sensor Endpoint: %d", electrical_endpoint_id);
}
cluster::electrical_power_measurement::config_t measurement_sensor_config;
esp_matter::cluster_t *energy_cluster = cluster::electrical_power_measurement::create(electrical_endpoint, &measurement_sensor_config, CLUSTER_FLAG_SERVER, cluster::electrical_power_measurement::feature::direct_current::get_id() | cluster::electrical_power_measurement::feature::alternating_current::get_id());
int64_t Voltaje = 0;
int64_t Watios = 0;
int64_t Amperios = 0;
int64_t WatiosAcumulados = 0;
cluster::electrical_power_measurement::attribute::create_voltage(energy_cluster, Voltaje);
cluster::electrical_power_measurement::attribute::create_active_power(energy_cluster, Watios);
cluster::electrical_power_measurement::attribute::create_active_current(energy_cluster, Amperios);
cluster::electrical_power_measurement::attribute::create_reactive_power(energy_cluster, WatiosAcumulados);
esp_openthread_platform_config_t config = {.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),};
set_openthread_platform_config(&config);
err = esp_matter::start(app_event_cb);
if(err==ESP_OK)
{
esp_matter::console::diagnostics_register_commands();
esp_matter::console::init();
}
else
{
ESP_LOGE(TAG, "Fallo en el arranque de Matter, err:%d", err);
}
}
else
{
ESP_LOGE(TAG, "Fallo al crear el nodo de Matter");
}
}
This is the log of the device
I (23) boot: ESP-IDF v5.2.2-dirty 2nd stage bootloader
I (23) boot: compile time Sep 2 2024 11:21:58
I (24) boot: chip revision: v0.0
I (26) boot.esp32c6: SPI Speed : 80MHz
I (31) boot.esp32c6: SPI Mode : DIO
I (36) boot.esp32c6: SPI Flash Size : 4MB
I (40) boot: Enabling RNG early entropy source...
I (46) boot: Partition Table:
I (49) boot: ## Label Usage Type ST Offset Length
I (57) boot: 0 esp_secure_cert unknown 3f 06 0000d000 00002000
I (64) boot: 1 nvs WiFi data 01 02 00010000 0000c000
I (72) boot: 2 nvs_keys NVS keys 01 04 0001c000 00001000
I (79) boot: 3 otadata OTA data 01 00 0001d000 00002000
I (87) boot: 4 phy_init RF data 01 01 0001f000 00001000
I (94) boot: 5 ota_0 OTA app 00 10 00020000 001e0000
I (101) boot: 6 ota_1 OTA app 00 11 00200000 001e0000
I (109) boot: 7 factoria WiFi data 01 02 003e0000 00006000
I (117) boot: 8 coredump Unknown data 01 03 003e6000 00010000
I (124) boot: End of partition table
I (129) esp_image: segment 0: paddr=00020020 vaddr=42140020 size=41358h (267096) map
I (192) esp_image: segment 1: paddr=00061380 vaddr=40800000 size=0ec98h ( 60568) load
I (207) esp_image: segment 2: paddr=00070020 vaddr=42000020 size=13f5f8h (1308152) map
I (478) esp_image: segment 3: paddr=001af620 vaddr=4080ec98 size=0620ch ( 25100) load
I (484) esp_image: segment 4: paddr=001b5834 vaddr=40814eb0 size=03100h ( 12544) load
I (488) esp_image: segment 5: paddr=001b893c vaddr=50000000 size=00004h ( 4) load
I (497) boot: Loaded app from partition at offset 0x20000
I (498) boot: Disabling RNG early entropy source...
I (504) cpu_start: Unicore app
I (516) cpu_start: Pro cpu start user code
I (518) cpu_start: cpu freq: 160000000 Hz
I (523) cpu_start: Application information:
I (528) cpu_start: Project name: light
I (533) cpu_start: App version: v7.0
I (537) cpu_start: Compile time: Sep 2 2024 11:30:26
I (544) cpu_start: ELF file SHA256: 7b5cae244...
I (549) cpu_start: ESP-IDF: v5.2.2-dirty
I (554) cpu_start: Min chip rev: v0.0
I (559) cpu_start: Max chip rev: v0.99
I (564) cpu_start: Chip rev: v0.0
I (569) heap_init: Initializing. RAM available for dynamic allocation:
I (576) heap_init: At 4082DF90 len 0004E680 (313 KiB): RAM
I (582) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (588) heap_init: At 50000004 len 00003FE4 (15 KiB): RTCRAM
I (595) spi_flash: detected chip: generic
I (599) spi_flash: flash io: dio
I (615) sleep: Configure to isolate all GPIO pins in sleep state
I (620) sleep: Enable automatic switching of GPIO sleep configuration
I (627) esp_core_dump_flash: Init core dump to flash
I (633) esp_core_dump_flash: Found partition 'coredump' @ 3e6000 65536 bytes
I (641) coexist: coex firmware version: d96c1e51f
I (641) coexist: coexist rom version 5b8dcfa
I (642) main_task: Started on CPU0
I (642) main_task: Calling app_main()
I (652) uart: queue free spaces: 20
I (652) app_driver: Starting PZEM004T ...
I (652) led_indicator: LED Indicator Version: 0.9.3
I (652) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (652) led_indicator: Indicator create successfully. type:LED Strips mode, hardware_data:0x40834320, blink_lists:custom
I (652) button: IoT Button Version: 3.3.1
I (652) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (662) app_main: Light Endpoint: 1
I (662) app_main: Electrical Sensor Endpoint: 2
W (662) esp_matter_core: Server Cluster 0x00000090 on endpoint 0x0002 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x0000FFFC on cluster 0x00000090 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x00000000 on cluster 0x00000090 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x00000001 on cluster 0x00000090 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x00000002 on cluster 0x00000090 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x00000008 on cluster 0x00000090 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x0000FFFD on cluster 0x00000090 already exists. Not creating again.
W (662) esp_matter_core: Attribute 0x00000008 on cluster 0x00000090 already exists. Not creating again.
I (692) chip[DL]: NVS set: chip-counters/reboot-count = 4 (0x4)
I (692) chip[DL]: Real time clock set to 946684800 (0100/00/01 00:00:00 UTC)
I (692) BLE_INIT: Using main XTAL as clock source
I (692) BLE_INIT: ble controller commit:[39c6e05]
I (692) phy_init: phy_version 290,81efd96,May 8 2024,10:42:13
I (732) OPENTHREAD: Host connection mode none
I (742) phy: libbtbb version: f97b181, May 8 2024, 10:42:29
I (752) NimBLE: GAP procedure initiated: stop advertising.
I (752) NimBLE: Failed to restore IRKs from store; status=8
I (752) CHIP[DL]: BLE host-controller synced
I (752) OPENTHREAD: OpenThread attached to netif
I (762) chip[DL]: OpenThread started: OK
I (762) chip[DL]: Setting OpenThread device type to ROUTER
I (1252) chip[SVR]: Subscription persistence not supported
I (1252) chip[SVR]: Server initializing...
I (1252) chip[TS]: Last Known Good Time: 2023-10-14T01:16:48
I (1252) chip[DMG]: AccessControl: initializing
I (1252) chip[DMG]: Examples::AccessControlDelegate::Init
I (1252) chip[DMG]: AccessControl: setting
I (1252) chip[DMG]: DefaultAclStorage: initializing
I (1252) chip[DMG]: DefaultAclStorage: 0 entries loaded
I (1262) chip[ZCL]: Using ZAP configuration...
I (1262) esp_matter_cluster: Cluster plugin init common callback
I (1262) chip[DMG]: AccessControlCluster: initializing
I (1262) chip[ZCL]: 0x4214785c ep 0 clus 0x0000_0030 attr 0x0000_0000 not supported
I (1262) chip[ZCL]: Initiating Admin Commissioning cluster.
I (1272) chip[DIS]: Updating services using commissioning mode 1
I (1272) chip[DIS]: Advertise commission parameter vendorID=65523 productID=32769 discriminator=3434/13 cm=1 cp=0
I (1272) chip[IN]: CASE Server enabling CASE session setups
I (1272) chip[SVR]: Joining Multicast groups
I (1272) chip[SVR]: Server Listening...
I (1272) esp_matter_core: Dynamic endpoint 0 added
I (1272) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000003's Attribute 0x00000001 is 0 **********
I (1272) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000004's Attribute 0x00000000 is 128 **********
I (1272) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000004's Attribute 0x0000FFFC is <invalid type: 0> **********
I (1272) chip[ZCL]: 0x4214785c ep 1 clus 0x0000_0062 attr 0x0000_0000 not supported
I (1272) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x0000FFFC is 1 **********
I (1272) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00004003 is 0 **********
I (1282) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00000000 is 0 **********
I (1282) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00000000 is 0 **********
I (1282) chip[ZCL]: Endpoint 1 On/off already set to new value
I (1282) esp_matter_core: Dynamic endpoint 1 added
I (1282) esp_matter_core: Dynamic endpoint 2 added
I (1282) chip[DL]: Configuring CHIPoBLE advertising (interval 25 ms, connectable)
I (1282) NimBLE: GAP procedure initiated: advertise;
I (1282) NimBLE: disc_mode=2
I (1282) NimBLE: adv_channel_map=0 own_addr_type=1 adv_filter_policy=0 adv_itvl_min=40 adv_itvl_max=40
I (1282) NimBLE:
I (1282) chip[DL]: CHIPoBLE advertising started
I (1282) app_main: Commissioning window opened
I (1282) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 0 **********
I (1282) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (1282) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (1282) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 is 0 **********
I (1332) main_task: Returned from app_main()
I (21382) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 0 **********
I (21382) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (21382) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (21382) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 is 0 **********
I (31282) chip[DL]: bleAdv Timeout : Start slow advertisement
I (31282) chip[DL]: Configuring CHIPoBLE advertising (interval 500 ms, connectable)
I (31282) chip[DL]: Device already advertising, stop active advertisement and restart
I (31282) NimBLE: GAP procedure initiated: stop advertising.
I (31282) NimBLE: GAP procedure initiated: advertise;
I (31282) NimBLE: disc_mode=2
I (31282) NimBLE: adv_channel_map=0 own_addr_type=1 adv_filter_policy=0 adv_itvl_min=800 adv_itvl_max=800
I (31282) NimBLE:
I (41482) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 0 **********
I (41482) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (41482) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (41482) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 is 0 **********
I (61582) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 0 **********
I (61582) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (61582) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (61582) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 is 0 **********
I (81682) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 0 **********
I (81682) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (81682) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (81682) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 is 0 **********
@JoseAntonioMG Yes electrical_power_measurement
is created by default when you create electrical_sensor
so you don’t need to create it again. Please close the issue if it is solved.
@jadhavrohit924 There are errors when updating the values of the "Electrical Power Measurement" endpoint.
I have removed the code fragment corresponding to the creation of the "Electrical_Power_Measurement" cluster and also the creation of attributes, since if I include them I also get the same errors.
extern "C" void app_main()
{
esp_err_t err = ESP_OK;
nvs_flash_init();
app_driver_handle_t electrical_sensor_handle = app_driver_PZEM004T_sensor_init();
app_driver_handle_t light_handle = app_driver_light_init();
app_driver_handle_t button_handle = app_driver_button_init();
app_reset_button_register(button_handle);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
if (node!=nullptr)
{
on_off_light::config_t on_off_light_config;
endpoint_t *light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, light_handle);
if (light_endpoint)
{
light_endpoint_id = endpoint::get_id(light_endpoint);
ESP_LOGI(TAG, "Light Endpoint: %d", light_endpoint_id);
}
electrical_sensor::config_t electrical_sensor_config;
endpoint_t *electrical_endpoint = electrical_sensor::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, electrical_sensor_handle);
if (electrical_endpoint)
{
electrical_endpoint_id = endpoint::get_id(electrical_endpoint);
ESP_LOGI(TAG, "Device energy management Endpoint: %d", electrical_endpoint_id);
}
esp_openthread_platform_config_t config = {.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),};
set_openthread_platform_config(&config);
err = esp_matter::start(app_event_cb);
if(err==ESP_OK)
{
esp_matter::console::diagnostics_register_commands();
esp_matter::console::init();
}
else
{
ESP_LOGE(TAG, "Fallo en el arranque de Matter, err:%d", err);
}
}
else
{
ESP_LOGE(TAG, "Fallo al crear el nodo de Matter");
}
}
This is the function that allows you to update attributes with energy consumption values.
static void PZEM004T(void *pvParameter)
{
struct current_values pzValues;
esp_matter_attr_val_t voltaje;
esp_matter_attr_val_t Amperios;
esp_matter_attr_val_t Watios;
esp_matter_attr_val_t WatiosAcumulados;
ESP_LOGI(TAG, "Starting PZEM004T ...");
while (1==1)
{
PzemGetValues(&pzValues);
voltaje = esp_matter_invalid(NULL);
voltaje.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
voltaje.val.i64 = pzValues.voltage;
Amperios = esp_matter_invalid(NULL);
Amperios.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
Amperios.val.i64 = pzValues.current;
Watios = esp_matter_invalid(NULL);
Watios.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
Watios.val.i64 = pzValues.power;
WatiosAcumulados = esp_matter_invalid(NULL);
WatiosAcumulados.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
WatiosAcumulados.val.i64 = pzValues.energy;
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::Voltage::Id, &voltaje);
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::ActiveCurrent::Id, &Amperios);
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::ActivePower::Id, &Watios);
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::ReactivePower::Id, &WatiosAcumulados);
vTaskDelay(DEFAULT_MEASURE_INTERVAL / portTICK_PERIOD_MS);
}
vTaskDelete(NULL);
}
Device log
I (23) boot: ESP-IDF v5.2.2-dirty 2nd stage bootloader
I (23) boot: compile time Sep 2 2024 11:21:58
I (24) boot: chip revision: v0.0
I (26) boot.esp32c6: SPI Speed : 80MHz
I (31) boot.esp32c6: SPI Mode : DIO
I (36) boot.esp32c6: SPI Flash Size : 4MB
I (40) boot: Enabling RNG early entropy source...
I (46) boot: Partition Table:
I (49) boot: ## Label Usage Type ST Offset Length
I (57) boot: 0 esp_secure_cert unknown 3f 06 0000d000 00002000
I (64) boot: 1 nvs WiFi data 01 02 00010000 0000c000
I (72) boot: 2 nvs_keys NVS keys 01 04 0001c000 00001000
I (79) boot: 3 otadata OTA data 01 00 0001d000 00002000
I (87) boot: 4 phy_init RF data 01 01 0001f000 00001000
I (94) boot: 5 ota_0 OTA app 00 10 00020000 001e0000
I (101) boot: 6 ota_1 OTA app 00 11 00200000 001e0000
I (109) boot: 7 factoria WiFi data 01 02 003e0000 00006000
I (117) boot: 8 coredump Unknown data 01 03 003e6000 00010000
I (124) boot: End of partition table
I (129) esp_image: segment 0: paddr=00020020 vaddr=42140020 size=41360h (267104) map
I (192) esp_image: segment 1: paddr=00061388 vaddr=40800000 size=0ec90h ( 60560) load
I (207) esp_image: segment 2: paddr=00070020 vaddr=42000020 size=13f530h (1307952) map
I (478) esp_image: segment 3: paddr=001af558 vaddr=4080ec90 size=06214h ( 25108) load
I (485) esp_image: segment 4: paddr=001b5774 vaddr=40814eb0 size=03100h ( 12544) load
I (489) esp_image: segment 5: paddr=001b887c vaddr=50000000 size=00004h ( 4) load
I (497) boot: Loaded app from partition at offset 0x20000
I (498) boot: Disabling RNG early entropy source...
I (504) cpu_start: Unicore app
I (516) cpu_start: Pro cpu start user code
I (519) cpu_start: cpu freq: 160000000 Hz
I (523) cpu_start: Application information:
I (528) cpu_start: Project name: light
I (533) cpu_start: App version: v7.0
I (538) cpu_start: Compile time: Sep 2 2024 11:30:26
I (544) cpu_start: ELF file SHA256: 596ebe44b...
I (549) cpu_start: ESP-IDF: v5.2.2-dirty
I (554) cpu_start: Min chip rev: v0.0
I (559) cpu_start: Max chip rev: v0.99
I (564) cpu_start: Chip rev: v0.0
I (569) heap_init: Initializing. RAM available for dynamic allocation:
I (576) heap_init: At 4082DF90 len 0004E680 (313 KiB): RAM
I (582) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (588) heap_init: At 50000004 len 00003FE4 (15 KiB): RTCRAM
I (595) spi_flash: detected chip: generic
I (599) spi_flash: flash io: dio
I (615) sleep: Configure to isolate all GPIO pins in sleep state
I (621) sleep: Enable automatic switching of GPIO sleep configuration
I (628) esp_core_dump_flash: Init core dump to flash
I (634) esp_core_dump_flash: Found partition 'coredump' @ 3e6000 65536 bytes
I (641) coexist: coex firmware version: d96c1e51f
I (641) coexist: coexist rom version 5b8dcfa
I (642) main_task: Started on CPU0
I (642) main_task: Calling app_main()
I (652) uart: queue free spaces: 20
I (652) app_driver: Starting PZEM004T ...
I (652) led_indicator: LED Indicator Version: 0.9.3
I (652) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (652) led_indicator: Indicator create successfully. type:LED Strips mode, hardware_data:0x40834320, blink_lists:custom
I (652) button: IoT Button Version: 3.3.1
I (652) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (662) app_main: Light Endpoint: 1
I (662) app_main: Device energy management Endpoint: 2
I (682) chip[DL]: NVS set: chip-counters/reboot-count = 4 (0x4)
I (682) chip[DL]: Real time clock set to 946684800 (0100/00/01 00:00:00 UTC)
I (682) BLE_INIT: Using main XTAL as clock source
I (682) BLE_INIT: ble controller commit:[39c6e05]
I (682) phy_init: phy_version 290,81efd96,May 8 2024,10:42:13
I (712) OPENTHREAD: Host connection mode none
I (732) phy: libbtbb version: f97b181, May 8 2024, 10:42:29
I (742) OPENTHREAD: OpenThread attached to netif
I (742) NimBLE: GAP procedure initiated: stop advertising.
I (742) NimBLE: Failed to restore IRKs from store; status=8
I (742) CHIP[DL]: BLE host-controller synced
I (742) chip[DL]: OpenThread started: OK
I (742) chip[DL]: Setting OpenThread device type to ROUTER
I (1252) chip[SVR]: Subscription persistence not supported
I (1252) chip[SVR]: Server initializing...
I (1252) chip[TS]: Last Known Good Time: 2023-10-14T01:16:48
I (1252) chip[DMG]: AccessControl: initializing
I (1252) chip[DMG]: Examples::AccessControlDelegate::Init
I (1252) chip[DMG]: AccessControl: setting
I (1252) chip[DMG]: DefaultAclStorage: initializing
I (1252) chip[DMG]: DefaultAclStorage: 0 entries loaded
I (1262) chip[ZCL]: Using ZAP configuration...
I (1262) esp_matter_cluster: Cluster plugin init common callback
I (1262) chip[DMG]: AccessControlCluster: initializing
I (1262) chip[ZCL]: 0x421475cc ep 0 clus 0x0000_0030 attr 0x0000_0000 not supported
I (1262) chip[ZCL]: Initiating Admin Commissioning cluster.
I (1272) chip[DIS]: Updating services using commissioning mode 1
I (1272) chip[DIS]: Advertise commission parameter vendorID=65523 productID=32773 discriminator=3434/13 cm=1 cp=0
I (1272) chip[IN]: CASE Server enabling CASE session setups
I (1272) chip[SVR]: Joining Multicast groups
I (1272) chip[SVR]: Server Listening...
I (1272) esp_matter_core: Dynamic endpoint 0 added
I (1272) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000003's Attribute 0x00000001 is 0 **********
I (1272) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000004's Attribute 0x00000000 is 128 **********
I (1272) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000004's Attribute 0x0000FFFC is <invalid type: 0> **********
I (1272) chip[ZCL]: 0x421475cc ep 1 clus 0x0000_0062 attr 0x0000_0000 not supported
I (1272) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x0000FFFC is 1 **********
I (1272) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00004003 is 0 **********
I (1282) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00000000 is 0 **********
I (1282) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00000000 is 0 **********
I (1282) chip[ZCL]: Endpoint 1 On/off already set to new value
I (1282) esp_matter_core: Dynamic endpoint 1 added
I (1282) esp_matter_core: Dynamic endpoint 2 added
I (1282) chip[DL]: Configuring CHIPoBLE advertising (interval 25 ms, connectable)
I (1282) NimBLE: GAP procedure initiated: advertise;
I (1282) NimBLE: disc_mode=2
I (1282) NimBLE: adv_channel_map=0 own_addr_type=1 adv_filter_policy=0 adv_itvl_min=40 adv_itvl_max=40
I (1282) NimBLE:
I (1282) chip[DL]: CHIPoBLE advertising started
I (1282) app_main: Commissioning window opened
I (1282) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0004 not supported
E (1282) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 to matter: 0x86
I (1282) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0005 not supported
E (1282) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 to matter: 0x86
I (1282) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (1282) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0009 not supported
E (1282) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 to matter: 0x86
I (1332) main_task: Returned from app_main()
> I (21392) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0004 not supported
E (21392) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 to matter: 0x86
I (21392) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0005 not supported
E (21392) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 to matter: 0x86
I (21392) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (21392) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0009 not supported
E (21392) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 to matter: 0x86
I (31282) chip[DL]: bleAdv Timeout : Start slow advertisement
I (31282) chip[DL]: Configuring CHIPoBLE advertising (interval 500 ms, connectable)
I (31282) chip[DL]: Device already advertising, stop active advertisement and restart
I (31282) NimBLE: GAP procedure initiated: stop advertising.
I (31282) NimBLE: GAP procedure initiated: advertise;
I (31282) NimBLE: disc_mode=2
I (31282) NimBLE: adv_channel_map=0 own_addr_type=1 adv_filter_policy=0 adv_itvl_min=800 adv_itvl_max=800
I (31282) NimBLE:
I (41492) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0004 not supported
E (41492) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 to matter: 0x86
I (41492) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0005 not supported
E (41492) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 to matter: 0x86
I (41492) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (41492) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0009 not supported
E (41492) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 to matter: 0x86
I (61592) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0004 not supported
E (61592) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 to matter: 0x86
I (61592) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0005 not supported
E (61592) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 to matter: 0x86
I (61592) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (61592) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0009 not supported
E (61592) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000009 to matter: 0x86
I (81692) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0004 not supported
E (81692) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 to matter: 0x86
I (81692) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0005 not supported
E (81692) esp_matter_attribute: Error updating Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 to matter: 0x86
I (81692) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 0 **********
I (81692) chip[ZCL]: 0x421475cc ep 2 clus 0x0000_0090 attr 0x0000_0009 not supported
@JoseAntonioMG, I suggest you first read the attribute list on that cluster and then add those attributes that are not on your device. Also while updating the attribute please refer to the code to update the attribute.
I have built a device with Esp32c6 and PZEM-004T to get the current and accumulated energy consumption in my house. This device works fine with arduino, however I want to implement Matter + thread technology in this device to connect it to other devices I have already created with esp matter.
I have developed a firmware from examples I have obtained from the internet with the "Electrical Energy Measurement" cluster, however it does not work.
app_main.cpp
In the code I am using this fragment which I don't know if it is correct
app_driver.cpp
pzem004tv3.cpp
pzem004tv3.h
The device starts correctly and can be commissioned with CHIP-TOOL, however it does not report data, such as the DC voltage of the electrical installation:
As can be seen, the function for obtaining data from the PZEM-004T is running correctly,
however the method:
does not collect the attributes correctly.
Can someone help me build the Matter schematic for obtaining energy data from pzem004t please.