espressif / esp-matter

Espressif's SDK for Matter
Apache License 2.0
648 stars 151 forks source link

How to get power consumption with Matter; watts, volts, amps, etc., etc. (CON-1314) #1063

Open JoseAntonioMG opened 3 weeks ago

JoseAntonioMG commented 3 weeks ago

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

#include "esp_matter_endpoint.h"
#include <esp_err.h>
#include <esp_log.h>
#include <nvs_flash.h>
#include <esp_matter.h>
#include <esp_matter_cluster.h>
#include <esp_matter_console.h>
#include <esp_matter_ota.h>
#include <common_macros.h>
#include <app_priv.h>
#include <app_reset.h>
#include <platform/ESP32/OpenthreadLauncher.h>
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
#include <app/server/Server.h>

static const char *TAG = "app_main";
using namespace esp_matter;
using namespace esp_matter::attribute;
using namespace esp_matter::endpoint;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::DiagnosticLogs;
constexpr auto k_timeout_seconds = 300;
uint16_t light_endpoint_id = 0;
extern uint16_t energy_sensor_endpoint_id = 0;

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;
    case chip::DeviceLayer::DeviceEventType::kFabricRemoved:
      ESP_LOGI(TAG, "Fabric removed successfully");
      if (chip::Server::GetInstance().GetFabricTable().FabricCount()==0)
      {
        chip::CommissioningWindowManager & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
        constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds);
        if (!commissionMgr.IsCommissioningWindowOpen())
        {
          CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds, chip::CommissioningWindowAdvertisement::kDnssdOnly);
          if (err!=CHIP_NO_ERROR)
          {
            ESP_LOGE(TAG, "Failed to open commissioning window, err:%" CHIP_ERROR_FORMAT, err.Format());
          }
        }
      }
      break;
    case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved:
      ESP_LOGI(TAG, "Fabric will be removed");
      break;
    case chip::DeviceLayer::DeviceEventType::kFabricUpdated:
      ESP_LOGI(TAG, "Fabric is updated");
      break;
    case chip::DeviceLayer::DeviceEventType::kFabricCommitted:
      ESP_LOGI(TAG, "Fabric is committed");
      break;
    case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized:
      ESP_LOGI(TAG, "BLE deinitialized and memory reclaimed");
      break;
    default:
      break;
  }
}

static esp_err_t app_identification_cb(identification::callback_type_t type, uint16_t endpoint_id, uint8_t effect_id, uint8_t effect_variant, void *priv_data)
{
  ESP_LOGI(TAG, "Identificacion de la llamada: tipo: %u, efecto: %u, variante: %u", type, effect_id, effect_variant);
  return ESP_OK;
}

static esp_err_t app_attribute_update_cb(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)
{
  esp_err_t err = ESP_OK;
  if (type==PRE_UPDATE)
  {
    app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data;
    err = app_driver_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val);
  }
  return err;
}

extern "C" void app_main()
{
  esp_err_t err = ESP_OK;
  nvs_flash_init();
  app_driver_handle_t energy_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);
    }
    power_source_device::config_t electrical_sensor_config;
    endpoint_t *energy_sensor_endpoint = power_source_device::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);
    }
    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");
  }
}

In the code I am using this fragment which I don't know if it is correct

    power_source_device::config_t electrical_sensor_config;
    endpoint_t *energy_sensor_endpoint = power_source_device::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);
    }

app_driver.cpp

#include "esp_matter_attribute_utils.h"
#include <esp_log.h>
#include <stdlib.h>
#include <string.h>
#include <esp_matter.h>
#include "app-common/zap-generated/ids/Attributes.h"
#include "app-common/zap-generated/ids/Clusters.h"
#include "bsp/esp-bsp.h"
#include "hal/uart_types.h"
#include <app_priv.h>
#include <esp_system.h>
#include <bmp280.h>
#include <pzem004tv3.h>

using namespace chip::app::Clusters;
using namespace esp_matter;
using namespace esp_matter::attribute;
using namespace esp_matter::endpoint;
static const char *TAG = "app_driver";
extern uint16_t light_endpoint_id;
extern uint16_t energy_sensor_endpoint_id;
#define BUF_SIZE (1024)
#define RD_BUF_SIZE (BUF_SIZE)
#define PATTERN_CHR_NUM (3)
static QueueHandle_t uart0_queue;

esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val)
{
  esp_err_t err = ESP_OK;
  if (endpoint_id==light_endpoint_id)
  {
    led_indicator_handle_t handle = (led_indicator_handle_t)driver_handle;
    bsp_led_set(handle, val->val.b);
  }
  if (endpoint_id==energy_sensor_endpoint_id)
  {
    ESP_LOGI(TAG, "La energia se ha actualizado a: %d", val->val.i16);
  }
  return err;
}

static void app_driver_button_toggle_cb(void *arg, void *data)
{
  ESP_LOGI(TAG, "Toggle button pressed");
  uint16_t endpoint_id = light_endpoint_id;
  uint32_t cluster_id = OnOff::Id;
  uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
  node_t *node = node::get();
  endpoint_t *endpoint = endpoint::get(node, endpoint_id);
  cluster_t *cluster = cluster::get(endpoint, cluster_id);
  attribute_t *attribute = attribute::get(cluster, attribute_id);
  esp_matter_attr_val_t val = esp_matter_invalid(NULL);
  attribute::get_val(attribute, &val);
  val.val.b = !val.val.b;
  attribute::update(endpoint_id, cluster_id, attribute_id, &val);
}

static void PZEM004T(void *pvParameter)
{
  struct current_values pzValues;
  esp_matter_attr_val_t voltaje_value;
  ESP_LOGI(TAG, "Starting PZEM004T ...");
  while (1==1)
  {
    PzemGetValues(&pzValues);
    ESP_LOGI(TAG, "=== Get electrical data ===");
    voltaje_value = esp_matter_invalid(NULL);
    voltaje_value.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT16;
    voltaje_value.val.i16 = pzValues.voltage;
    esp_matter::attribute::update(energy_sensor_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::Voltage::Id, &voltaje_value);
    vTaskDelay(DEFAULT_MEASURE_INTERVAL / portTICK_PERIOD_MS);
  }
  vTaskDelete(NULL);
}

app_driver_handle_t app_driver_light_init()
{
  led_indicator_handle_t leds[CONFIG_BSP_LEDS_NUM];
  ESP_ERROR_CHECK(bsp_led_indicator_create(leds, NULL, CONFIG_BSP_LEDS_NUM));
  return (app_driver_handle_t)leds[0];
}

app_driver_handle_t app_driver_button_init()
{
  button_handle_t btns[BSP_BUTTON_NUM];
  ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
  ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL));
  return (app_driver_handle_t)btns[0];
}

app_driver_handle_t app_driver_PZEM004T_sensor_init()
{
  uart_config_t uart_config = {.baud_rate = 9600, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .source_clk = UART_SCLK_DEFAULT,};
  uart_driver_install(UART_NUM_0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
  uart_param_config(UART_NUM_0, &uart_config);
  esp_log_level_set(TAG, ESP_LOG_INFO);
  uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
  uart_enable_pattern_det_baud_intr(UART_NUM_0, '+', PATTERN_CHR_NUM, 9, 0, 0);
  uart_pattern_queue_reset(UART_NUM_0, 20);
  xTaskCreatePinnedToCore(&PZEM004T, "PZEM004T", configMINIMAL_STACK_SIZE * 8, NULL, 5, NULL, 0);
  return (app_driver_handle_t)1;
}

pzem004tv3.cpp

#include "pzem004tv3.h"
#include "hal/uart_types.h"
#include "soc/clk_tree_defs.h"

static uint16_t crc16(const uint8_t *data, uint16_t len);
static const char *TAG = "PZEM-004T";

uint8_t PzReadAddress()
{
    static uint8_t response[7] = {0};
    memset(response, 0, sizeof(response));
    uint8_t addr = 0;
    if (!PzemSendCmd8(CMD_RHR, WREG_ADDR, 0x01, false, 0xFFFF))
    {
        return INVALID_ADDRESS;
    }
    if (uart_read_bytes(UART_NUM_0, response, 7, pdMS_TO_TICKS(PZ_READ_TIMEOUT)) != 7)
    {
        return INVALID_ADDRESS;
    }
    addr = ((uint32_t) response[3] << 8 | (uint32_t) response[4]);
    return addr;
}

bool PzSetAddress(uint8_t new_addr)
{
    if (new_addr < 0x01 || new_addr > 0xF7)
    {
        ESP_LOGI(TAG, "Address failed sanity check");
        return false;
    }
    if (PZ_DEFAULT_ADDRESS  == new_addr)
    {
        ESP_LOGI(TAG, "New address is the same as the old address");
        return false;
    }
    if (!PzemSendCmd8( CMD_WSR, WREG_ADDR, new_addr, true, 0xFFFF ))
    {
        ESP_LOGE(TAG, "Failed to set the new address !!!!");
        return false;
    }
    return true;
}

bool PzResetEnergy()
{
    uint8_t buffer[4] = {0};
    uint8_t reply[5] = {0};
    memset(buffer, 0, sizeof(buffer));
    memset(reply, 0, sizeof(reply));
    buffer[0] = PZ_DEFAULT_ADDRESS;
    buffer[1] = 0x00;
    buffer[2] = CMD_REST;
    buffer[3] = 0x00;
    buffer[4] = 0x00;
    (void)PzemSetCRC( buffer, 4 );
    if (uart_write_bytes(UART_NUM_0, buffer, 4) == -1)
    {
        ESP_LOGE(TAG, "Failed to write to sensor/UART !!");
    }
    uint16_t length = uart_read_bytes(UART_NUM_0, reply, 5, pdMS_TO_TICKS(PZ_READ_TIMEOUT));
    if ((length == 0) || (length == 5))
    {
        return false;
    }
    return true;
}

bool PzemSendCmd8(uint8_t cmd, uint16_t regAddr, uint16_t regVal, bool check, uint16_t slave_addr)
{
    uint8_t txdata[TX_BUF_SIZE] = {0};
    uint8_t rxdata[RX_BUF_SIZE] = {0};
    memset(txdata, 0, sizeof(txdata));
    memset(rxdata, 0, sizeof(rxdata));
    if ((slave_addr == 0xFFFF) || (slave_addr < 0x01) || (slave_addr > 0xF7))
    {
        slave_addr = PZ_DEFAULT_ADDRESS;
    }
    txdata[0] = slave_addr;
    txdata[1] = cmd;
    txdata[2] = (regAddr >> 8) & 0xFF;
    txdata[3] = (regAddr) & 0xFF;
    txdata[4] = (regVal >> 8) & 0xFF;
    txdata[5] = (regVal) & 0xFF;
    (void)PzemSetCRC(txdata, TX_BUF_SIZE);
    const int txBytes = uart_write_bytes(UART_NUM_0, txdata, TX_BUF_SIZE);
    if (check)
    {
        if (!uart_read_bytes(UART_NUM_0, rxdata, RX_BUF_SIZE, pdMS_TO_TICKS(PZ_READ_TIMEOUT)))
        {
            return false;
        }
        for (uint8_t i = 0; i < 8; i++)
        {
            if (txdata[i] != rxdata[i])
            {
                return false;
            }
        }
    }
    return true;
}

bool PzemGetValues(current_values_t *pmonValues)
{
    PzemZeroValues((current_values_t *) pmonValues);
    uint8_t respbuff[RESP_BUF_SIZE] = {0};
    memset(respbuff, 0, sizeof(respbuff));
    if (PzemSendCmd8(CMD_RIR, 0x00, 0x0A, false, 0xFFFF ) == false)
    {
        ESP_LOGE(TAG, "Error writing to registers !!");
    }
    if (uart_read_bytes(UART_NUM_0, respbuff, RESP_BUF_SIZE, pdMS_TO_TICKS(PZ_READ_TIMEOUT)) != RESP_BUF_SIZE)

    {
        return false;
    }
    if ( !PzemCheckCRC( respbuff, RESP_BUF_SIZE ) )
    {
        ESP_LOGV(TAG, "Retreived buffer CRC check failed");
        return false;
    }
    else
    {
        ESP_LOGI(TAG, "CRC check OK for GetValues()");
    }
    pmonValues->voltage = ( ( uint32_t ) respbuff[ 3 ] << 8 | ( uint32_t ) respbuff[ 4 ] ) / 10.0;
    pmonValues->current = ( ( uint32_t ) respbuff[ 5 ] << 8 | ( uint32_t ) respbuff[ 6 ] | ( uint32_t ) respbuff[ 7 ] << 24 | ( uint32_t ) respbuff[ 8 ] << 16 ) / 1000.0;
    pmonValues->power = ( ( uint32_t ) respbuff[ 9 ] << 8 | ( uint32_t ) respbuff[ 10 ] | ( uint32_t ) respbuff[ 11 ] << 24 | ( uint32_t ) respbuff[ 12 ] << 16 ) / 10.0;
    pmonValues->energy = ( ( uint32_t ) respbuff[ 13 ] << 8 | ( uint32_t ) respbuff[ 14 ] | ( uint32_t ) respbuff[ 15 ] << 24 | ( uint32_t ) respbuff[ 16 ] << 16 ) / 1000.0;
    pmonValues->frequency = ( ( uint32_t ) respbuff[ 17 ] << 8 | ( uint32_t ) respbuff[ 18 ] ) / 10.0;
    pmonValues->pf = ( ( uint32_t ) respbuff[ 19 ] << 8 | ( uint32_t ) respbuff[ 20 ] ) / 100.0;
    pmonValues->alarms = ( ( uint32_t ) respbuff[ 21 ] << 8 | ( uint32_t ) respbuff[ 22 ] );
    pmonValues->apparent_power = (pmonValues->voltage * pmonValues->current);
    pmonValues->fi = 360.0F * (acosf(pmonValues->pf) / (2.0F * 3.14159265F));
    pmonValues->reactive_power = pmonValues->apparent_power * sinf(pmonValues->fi);
    return true;
}

void PzemSetCRC(uint8_t *buf, uint16_t len)
{
    uint64_t start = esp_timer_get_time();
    if (len <= 2)
    {
        return;
    }
    uint16_t crc = crc16(buf, len - 2);
    buf[len - 2] = crc & 0xFF;
    buf[len - 1] = (crc >> 8) & 0xFF;
    uint64_t stop = esp_timer_get_time();
}

bool PzemCheckCRC( const uint8_t *buf, uint16_t len )
{
    uint64_t start = esp_timer_get_time();
    if ( len <= 2 )
    {
        return false;
    }
    uint16_t crc = crc16( buf, len - 2 );
    uint64_t stop = esp_timer_get_time();
    return ( ( uint16_t ) buf[ len - 2 ] | ( uint16_t ) buf[ len - 1 ] << 8 ) == crc;
}

void PzemZeroValues(current_values_t *currentValues)
{
    currentValues->alarms = 0;
    currentValues->current = 0.0f;
    currentValues->energy = 0.0f;
    currentValues->frequency = 0.0f;
    currentValues->pf = 0.0f;
    currentValues->power = 0.0f;
    currentValues->voltage = 0.0f;
    currentValues->apparent_power = 0.0f;
    currentValues->reactive_power = 0.0f;
    currentValues->fi = 0.0f;
}

static uint16_t crc16(const uint8_t *data, uint16_t len)
{
    uint8_t nTemp;
    uint16_t crc = 0xFFFF;
    while (len--)
    {
        nTemp = *data++ ^ crc;
        crc >>= 8;
        crc ^= (uint16_t)pgm_read_word(&crcTable[nTemp]);
    }
    return crc;
}

pzem004tv3.h

#pragma once
#include <math.h>
#include <string.h>
#include "driver/uart.h"
#include "driver/gpio.h"
#include "hal/gpio_hal.h"
#include "hal/uart_ll.h"
#include "esp_timer.h"
#include "esp_log.h"

#define RX_BUF_SIZE      8
#define TX_BUF_SIZE      8
#define RESP_BUF_SIZE    25
#define UPDATE_TIME      200
typedef struct current_values
{
    float voltage;
    float current;
    float power;
    float energy;
    float frequency;
    float pf;
    float apparent_power;
    float reactive_power;
    float fi;
    uint16_t alarms;
} current_values_t;
bool PzemCheckCRC(const uint8_t *buf, uint16_t len);
uint16_t PzemReceive(uint8_t *resp, uint16_t len);
bool PzemSendCmd8(uint8_t cmd, uint16_t rAddr, uint16_t val, bool check, uint16_t slave_addr);
void PzemSetCRC(uint8_t *buf, uint16_t len);
bool PzemGetValues(current_values_t *pmonValues);
uint8_t PzReadAddress();
bool PzResetEnergy();
void PzemZeroValues(current_values_t *currentValues);
bool PzSetAddress(uint8_t new_addr);
#define millis( x ) ( esp_timer_get_time( x ) / 1000 )
#define PZ_DEFAULT_ADDRESS    0xF8
#define PZ_BAUD_RATE          9600
#define PZ_READ_TIMEOUT       100
#define RG_VOLTAGE            0x0000
#define RG_CURRENT_L          0x0001
#define RG_CURRENT_H          0X0002
#define RG_POWER_L            0x0003
#define RG_POWER_H            0x0004
#define RG_ENERGY_L           0x0005
#define RG_ENERGY_H           0x0006
#define RG_FREQUENCY          0x0007
#define RG_PF                 0x0008
#define RG_ALARM              0x0009
#define CMD_RHR               0x03
#define CMD_RIR               0X04
#define CMD_WSR               0x06
#define CMD_CAL               0x41
#define CMD_REST              0x42
#define WREG_ALARM_THR        0x0001
#define WREG_ADDR             0x0002
#define INVALID_ADDRESS       0x00
#define PROGMEM
#define pgm_read_byte(x)      ( *( x ) )
#define pgm_read_word(x)      ( *( x ) )
#define pgm_read_float(x)     ( *( x ) )
#define PSTR(STR)             STR

static const DRAM_ATTR uint16_t crcTable[] =
{
    0X0000, 0XC0C1, 0XC181, 0X0140, 0XC301, 0X03C0, 0X0280, 0XC241,
    0XC601, 0X06C0, 0X0780, 0XC741, 0X0500, 0XC5C1, 0XC481, 0X0440,
    0XCC01, 0X0CC0, 0X0D80, 0XCD41, 0X0F00, 0XCFC1, 0XCE81, 0X0E40,
    0X0A00, 0XCAC1, 0XCB81, 0X0B40, 0XC901, 0X09C0, 0X0880, 0XC841,
    0XD801, 0X18C0, 0X1980, 0XD941, 0X1B00, 0XDBC1, 0XDA81, 0X1A40,
    0X1E00, 0XDEC1, 0XDF81, 0X1F40, 0XDD01, 0X1DC0, 0X1C80, 0XDC41,
    0X1400, 0XD4C1, 0XD581, 0X1540, 0XD701, 0X17C0, 0X1680, 0XD641,
    0XD201, 0X12C0, 0X1380, 0XD341, 0X1100, 0XD1C1, 0XD081, 0X1040,
    0XF001, 0X30C0, 0X3180, 0XF141, 0X3300, 0XF3C1, 0XF281, 0X3240,
    0X3600, 0XF6C1, 0XF781, 0X3740, 0XF501, 0X35C0, 0X3480, 0XF441,
    0X3C00, 0XFCC1, 0XFD81, 0X3D40, 0XFF01, 0X3FC0, 0X3E80, 0XFE41,
    0XFA01, 0X3AC0, 0X3B80, 0XFB41, 0X3900, 0XF9C1, 0XF881, 0X3840,
    0X2800, 0XE8C1, 0XE981, 0X2940, 0XEB01, 0X2BC0, 0X2A80, 0XEA41,
    0XEE01, 0X2EC0, 0X2F80, 0XEF41, 0X2D00, 0XEDC1, 0XEC81, 0X2C40,
    0XE401, 0X24C0, 0X2580, 0XE541, 0X2700, 0XE7C1, 0XE681, 0X2640,
    0X2200, 0XE2C1, 0XE381, 0X2340, 0XE101, 0X21C0, 0X2080, 0XE041,
    0XA001, 0X60C0, 0X6180, 0XA141, 0X6300, 0XA3C1, 0XA281, 0X6240,
    0X6600, 0XA6C1, 0XA781, 0X6740, 0XA501, 0X65C0, 0X6480, 0XA441,
    0X6C00, 0XACC1, 0XAD81, 0X6D40, 0XAF01, 0X6FC0, 0X6E80, 0XAE41,
    0XAA01, 0X6AC0, 0X6B80, 0XAB41, 0X6900, 0XA9C1, 0XA881, 0X6840,
    0X7800, 0XB8C1, 0XB981, 0X7940, 0XBB01, 0X7BC0, 0X7A80, 0XBA41,
    0XBE01, 0X7EC0, 0X7F80, 0XBF41, 0X7D00, 0XBDC1, 0XBC81, 0X7C40,
    0XB401, 0X74C0, 0X7580, 0XB541, 0X7700, 0XB7C1, 0XB681, 0X7640,
    0X7200, 0XB2C1, 0XB381, 0X7340, 0XB101, 0X71C0, 0X7080, 0XB041,
    0X5000, 0X90C1, 0X9181, 0X5140, 0X9301, 0X53C0, 0X5280, 0X9241,
    0X9601, 0X56C0, 0X5780, 0X9741, 0X5500, 0X95C1, 0X9481, 0X5440,
    0X9C01, 0X5CC0, 0X5D80, 0X9D41, 0X5F00, 0X9FC1, 0X9E81, 0X5E40,
    0X5A00, 0X9AC1, 0X9B81, 0X5B40, 0X9901, 0X59C0, 0X5880, 0X9841,
    0X8801, 0X48C0, 0X4980, 0X8941, 0X4B00, 0X8BC1, 0X8A81, 0X4A40,
    0X4E00, 0X8EC1, 0X8F81, 0X4F40, 0X8D01, 0X4DC0, 0X4C80, 0X8C41,
    0X4400, 0X84C1, 0X8581, 0X4540, 0X8701, 0X47C0, 0X4680, 0X8641,
    0X8201, 0X42C0, 0X4380, 0X8341, 0X4100, 0X81C1, 0X8081, 0X4040
};

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:

I (23) boot: ESP-IDF v5.2.2-dirty 2nd stage bootloader
I (23) boot: compile time Aug 22 2024 20:18:15
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=40ed0h (265936) map
I (192) esp_image: segment 1: paddr=00060ef8 vaddr=40800000 size=0f120h ( 61728) load
I (207) esp_image: segment 2: paddr=00070020 vaddr=42000020 size=13e718h (1304344) map
I (477) esp_image: segment 3: paddr=001ae740 vaddr=4080f120 size=05d84h ( 23940) load
I (484) esp_image: segment 4: paddr=001b44cc vaddr=40814eb0 size=03100h ( 12544) load
I (488) esp_image: segment 5: paddr=001b75d4 vaddr=50000000 size=00004h (     4) load
I (496) boot: Loaded app from partition at offset 0x20000
I (497) 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 (527) cpu_start: Project name:     light
I (532) cpu_start: App version:      v7.0
I (537) cpu_start: Compile time:     Aug 22 2024 20:26:26
I (543) cpu_start: ELF file SHA256:  b38a40e80...
I (548) cpu_start: ESP-IDF:          v5.2.2-dirty
I (554) cpu_start: Min chip rev:     v0.0
I (558) cpu_start: Max chip rev:     v0.99 
I (563) cpu_start: Chip rev:         v0.0
I (568) heap_init: Initializing. RAM available for dynamic allocation:
I (575) heap_init: At 4082DF90 len 0004E680 (313 KiB): RAM
I (581) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (587) heap_init: At 50000004 len 00003FE4 (15 KiB): RTCRAM
I (594) spi_flash: detected chip: generic
I (598) spi_flash: flash io: dio
I (614) 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 (640) coexist: coex firmware version: d96c1e51f
I (641) coexist: coexist rom version 5b8dcfa
I (641) main_task: Started on CPU0
I (641) main_task: Calling app_main()
I (651) uart: queue free spaces: 20
I (661) app_driver: Starting PZEM004T ...
I (661) led_indicator: LED Indicator Version: 0.9.3
I (661) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (661) led_indicator: Indicator create successfully. type:LED Strips mode, hardware_data:0x40834530, blink_lists:custom
I (661) button: IoT Button Version: 3.2.3
I (661) gpio: GPIO[9]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (661) app_main: Dispositivo - Luz Ambiente. Creado el punto final: 1
I (661) app_main: Dispositivo - Energia. Creado el punto final 2
I (691) chip[DL]: NVS set: chip-counters/reboot-count = 16 (0x10)
I (691) chip[DL]: Real time clock set to 946684800 (0100/00/01 00:00:00 UTC)
I (691) BLE_INIT: Using main XTAL as clock source
I (691) BLE_INIT: ble controller commit:[39c6e05]
I (691) phy_init: phy_version 290,81efd96,May  8 2024,10:42:13
I (701) OPENTHREAD: Host connection mode none
I (741) phy: libbtbb version: f97b181, May  8 2024, 10:42:29
I (741) NimBLE: GAP procedure initiated: stop advertising.
I (741) NimBLE: Failed to restore IRKs from store; status=8
I (741) CHIP[DL]: BLE host-controller synced
I (761) app_driver: === Get electrical data ===
I (761) OPENTHREAD: OpenThread attached to netif
I(761) OPENTHREAD:[N] Mle-----------: Role disabled -> detached
I (781) chip[DL]: OpenThread ifconfig up and thread start
I (781) chip[DL]: OpenThread started: OK
I (781) chip[DL]: Setting OpenThread device type to ROUTER
I (791) OT_STATE: netif up
I(991) OPENTHREAD:[N] Mle-----------: Role detached -> router
I(991) OPENTHREAD:[N] Mle-----------: Partition ID 0x5155e9b8
I (1041) chip[DL]: SRP Client was started, detected server: fd00:0db8:00a0:0000:c3aa:26cb:758e:c359
I (1261) chip[SVR]: Subscription persistence not supported
I (1261) chip[SVR]: Server initializing...
I (1261) chip[TS]: Last Known Good Time: 2023-10-14T01:16:48
I (1271) chip[FP]: Fabric index 0x3 was retrieved from storage. Compressed FabricId 0x31B1EDA48C03DB25, FabricId 0x0000000000000001, NodeId 0x0000000000000003, VendorId 0xFFF1
I (1271) chip[DMG]: AccessControl: initializing
I (1271) chip[DMG]: Examples::AccessControlDelegate::Init
I (1271) chip[DMG]: AccessControl: setting
I (1271) chip[DMG]: DefaultAclStorage: initializing
I (1271) chip[DMG]: DefaultAclStorage: 1 entries loaded
I (1291) chip[ZCL]: Using ZAP configuration...
I (1291) esp_matter_cluster: Cluster plugin init common callback
I (1291) chip[DMG]: AccessControlCluster: initializing
I (1291) chip[ZCL]: 0x42147614 ep 0 clus 0x0000_0030 attr 0x0000_0000 not supported
I (1291) chip[ZCL]: Initiating Admin Commissioning cluster.
I (1291) chip[SVR]: Fabric already commissioned. Disabling BLE advertisement
I (1291) chip[IN]: CASE Server enabling CASE session setups
I (1291) chip[SVR]: Joining Multicast groups
I (1291) chip[SVR]: Server Listening...
I (1291) chip[DIS]: Updating services using commissioning mode 0
I (1291) chip[DIS]: Advertise operational node 31B1EDA48C03DB25-0000000000000003
I (1291) chip[DIS]: Advertise commission parameter vendorID=65523 productID=32800 discriminator=3434/13 cm=0 cp=0
I (1301) esp_matter_core: Dynamic endpoint 0 added
I (1301) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000003's Attribute 0x00000001 is 0 **********
I (1301) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000004's Attribute 0x00000000 is 128 **********
I (1301) esp_matter_attribute: ********** W : Endpoint 0x0001's Cluster 0x00000004's Attribute 0x0000FFFC is <invalid type: 0> **********
I (1301) chip[ZCL]: 0x42147614 ep 1 clus 0x0000_0062 attr 0x0000_0000 not supported
I (1301) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x0000FFFC is 1 **********
I (1301) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00004003 is 0 **********
I (1301) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00000000 is 0 **********
I (1301) esp_matter_attribute: ********** R : Endpoint 0x0001's Cluster 0x00000006's Attribute 0x00000000 is 0 **********
I (1301) chip[ZCL]: Endpoint 1 On/off already set to new value
I (1301) esp_matter_core: Dynamic endpoint 1 added
I (1301) esp_matter_core: Dynamic endpoint 2 added
I (1361) main_task: Returned from app_main()
I (2161) chip[DIS]: Updating services using commissioning mode 0
I (2171) chip[DIS]: Advertise operational node 31B1EDA48C03DB25-0000000000000003
I (2171) chip[DL]: advertising srp service: 31B1EDA48C03DB25-0000000000000003._matter._tcp
I (2171) chip[DIS]: Advertise commission parameter vendorID=65523 productID=32800 discriminator=3434/13 cm=0 cp=0
I (2171) chip[DL]: advertising srp service: 1206E0271A848CF5._matterc._udp
I (2171) chip[SVR]: Server initialization complete
I (2181) chip[SWU]: Stopping the watchdog timer
I (2181) chip[SWU]: Starting the periodic query timer, timeout: 86400 seconds
I (2181) esp_matter_attribute: ********** R : Endpoint 0x0000's Cluster 0x0000002A's Attribute 0x00000002 is 0 **********
I (2181) esp_matter_attribute: ********** W : Endpoint 0x0000's Cluster 0x0000002A's Attribute 0x00000002 is 1 **********
I (2181) esp_matter_attribute: ********** R : Endpoint 0x0000's Cluster 0x0000002A's Attribute 0x00000003 is null **********
I (21411) app_driver: === Get electrical data ===
I (41511) app_driver: === Get electrical data ===
I (61611) app_driver: === Get electrical data ===
I (81711) app_driver: === Get electrical data ===

As can be seen, the function for obtaining data from the PZEM-004T is running correctly,

I (21411) app_driver: === Get electrical data ===
I (41511) app_driver: === Get electrical data ===
I (61611) app_driver: === Get electrical data ===
I (81711) app_driver: === Get electrical data ===

however the method:

esp_matter::attribute::update(energy_sensor_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::Voltage::Id, &voltaje_value);

does not collect the attributes correctly.

Can someone help me build the Matter schematic for obtaining energy data from pzem004t please.

jadhavrohit924 commented 2 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.

jadhavrohit924 commented 2 weeks ago

@JoseAntonioMG In your code, you have created a PowerSource device type and are updating the attribute of the ElectricalPowerMeasurement Cluster.

  1. You have to create an accurate device type first.
  2. Add appropriate attributes, that you want to use and then try to update those attributes.
JoseAntonioMG commented 2 weeks ago

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.

jadhavrohit924 commented 2 weeks ago

@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.

JoseAntonioMG commented 2 weeks ago

Does this mean I need to create the optional attributes for the Matter SDK? How can I create the voltage attribute?

JoseAntonioMG commented 2 weeks ago

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);
    }
  }
jadhavrohit924 commented 2 weeks ago

Please go through the docs of create your own data model.

JoseAntonioMG commented 2 weeks ago

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

jadhavrohit924 commented 1 week ago

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.

JoseAntonioMG commented 1 week ago

@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 **********
jadhavrohit924 commented 1 week ago

@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.

JoseAntonioMG commented 1 week ago

@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
jadhavrohit924 commented 1 week ago

@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.