-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding carbon dioxide cluster makes the device crash (TZ-1432) #518
Comments
The code you provided appears correct upon review. However, the crash log lacks some critical information, you could also try increasing the Zigbee task stack size to see if it resolves the issue. BTW, does the crash occur when adding the CO2 cluster or during the CO2 reporting process? Could you please share more detailed code to help us identify the root cause of the crash? Ideally, providing a reproducible code snippet would be very helpful. |
Hi, Here's a full code with no sensor and hardcoded values: #include "esp_check.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "ha/esp_zigbee_ha_standard.h"
#include "esp_zb_sen66.h"
#include "string.h"
#if !defined ZB_ED_ROLE
#error Define ZB_ED_ROLE in idf.py menuconfig to compile sensor (End Device) source code.
#endif
#define DEFINE_PSTRING(var, str) \
const struct \
{ \
unsigned char len; \
char content[sizeof(str)]; \
}(var) = {sizeof(str) - 1, (str)}
static const char *TAG = "ESP_ZB_SEN66_SENSOR";
#define ESP_ZB_ZCL_CLUSTER_ID_PM10_MEASUREMENT 0x042dU
#define ESP_ZB_ZCL_ATTR_PM10_MEASUREMENT_MEASURED_VALUE_ID 0x0000
#define ESP_ZB_ZCL_CLUSTER_ID_VOC_MEASUREMENT 26113
#define ESP_ZB_ZCL_ATTR_VOC_MEASUREMENT_MEASURED_VALUE_ID 0x0000
void reportAttribute(uint16_t clusterID, uint16_t attributeID, void *value, uint8_t value_length)
{
esp_zb_zcl_report_attr_cmd_t cmd = {
.zcl_basic_cmd = {
.dst_addr_u.addr_short = 0x0000,
.dst_endpoint = HA_ESP_SENSOR_ENDPOINT,
.src_endpoint = HA_ESP_SENSOR_ENDPOINT,
},
.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT,
.clusterID = clusterID,
.attributeID = attributeID,
.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV,
};
esp_zb_zcl_attr_t *value_r = esp_zb_zcl_get_attribute(HA_ESP_SENSOR_ENDPOINT, clusterID, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, attributeID);
memcpy(value_r->data_p, value, value_length);
esp_zb_zcl_report_attr_cmd_req(&cmd);
}
void reportValue(uint16_t cluserID, uint16_t valueID, void *value)
{
//esp_zb_lock_acquire(portMAX_DELAY);
esp_zb_zcl_set_attribute_val(
HA_ESP_SENSOR_ENDPOINT,
cluserID,
ESP_ZB_ZCL_CLUSTER_SERVER_ROLE,
valueID,
value,
false
);
// esp_zb_lock_release();
}
static void bdb_start_top_level_commissioning_cb(uint8_t mode_mask)
{
ESP_RETURN_ON_FALSE(esp_zb_bdb_start_top_level_commissioning(mode_mask) == ESP_OK, ,
TAG, "Failed to start Zigbee bdb commissioning");
}
void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct)
{
uint32_t *p_sg_p = signal_struct->p_app_signal;
esp_err_t err_status = signal_struct->esp_err_status;
esp_zb_app_signal_type_t sig_type = *p_sg_p;
switch (sig_type) {
case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP:
ESP_LOGI(TAG, "Initialize Zigbee stack");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_INITIALIZATION);
break;
case ESP_ZB_BDB_SIGNAL_DEVICE_FIRST_START:
case ESP_ZB_BDB_SIGNAL_DEVICE_REBOOT:
if (err_status == ESP_OK) {
ESP_LOGI(TAG, "Device started up in%s factory-reset mode", esp_zb_bdb_is_factory_new() ? "" : " non");
if (esp_zb_bdb_is_factory_new()) {
ESP_LOGI(TAG, "Start network steering");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
} else {
ESP_LOGI(TAG, "Device rebooted");
}
} else {
ESP_LOGW(TAG, "%s failed with status: %s, retrying", esp_zb_zdo_signal_to_string(sig_type),
esp_err_to_name(err_status));
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb,
ESP_ZB_BDB_MODE_INITIALIZATION, 1000);
}
break;
case ESP_ZB_BDB_SIGNAL_STEERING:
if (err_status == ESP_OK) {
esp_zb_ieee_addr_t extended_pan_id;
esp_zb_get_extended_pan_id(extended_pan_id);
ESP_LOGI(TAG, "Joined network successfully (Extended PAN ID: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, PAN ID: 0x%04hx, Channel:%d, Short Address: 0x%04hx)",
extended_pan_id[7], extended_pan_id[6], extended_pan_id[5], extended_pan_id[4],
extended_pan_id[3], extended_pan_id[2], extended_pan_id[1], extended_pan_id[0],
esp_zb_get_pan_id(), esp_zb_get_current_channel(), esp_zb_get_short_address());
} else {
ESP_LOGI(TAG, "Network steering was not successful (status: %s)", esp_err_to_name(err_status));
esp_zb_scheduler_alarm((esp_zb_callback_t)bdb_start_top_level_commissioning_cb, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000);
}
break;
default:
ESP_LOGI(TAG, "ZDO signal: %s (0x%x), status: %s", esp_zb_zdo_signal_to_string(sig_type), sig_type,
esp_err_to_name(err_status));
break;
}
}
static esp_zb_cluster_list_t *custom_sensor_clusters_create()
{
esp_zb_basic_cluster_cfg_t basic_cfg;
esp_zb_identify_cluster_cfg_t identify_cfg;
esp_zb_cluster_list_t *cluster_list = esp_zb_zcl_cluster_list_create();
esp_zb_attribute_list_t *basic_cluster = esp_zb_basic_cluster_create(&basic_cfg);
DEFINE_PSTRING(ManufacturerName, "CustomSensor");
ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)&ManufacturerName));
ESP_ERROR_CHECK(esp_zb_basic_cluster_add_attr(basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, MODEL_IDENTIFIER));
ESP_ERROR_CHECK(esp_zb_cluster_list_add_basic_cluster(cluster_list, basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE));
ESP_ERROR_CHECK(esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(&identify_cfg), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE));
ESP_ERROR_CHECK(esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY), ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE));
esp_zb_temperature_meas_cluster_cfg_t temperature_meas_cfg = {
.measured_value = 0xFFFF,
.min_value = -1000,
.max_value = 6000,
};
ESP_ERROR_CHECK(esp_zb_cluster_list_add_temperature_meas_cluster(
cluster_list,
esp_zb_temperature_meas_cluster_create(&temperature_meas_cfg),
ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
));
ESP_LOGI(TAG, "Temperature measurement cluster added");
esp_zb_humidity_meas_cluster_cfg_t humidity_meas_cfg = {
.measured_value = 0xFFFF,
.min_value = 0,
.max_value = 65535,
};
ESP_ERROR_CHECK(esp_zb_cluster_list_add_humidity_meas_cluster(
cluster_list,
esp_zb_humidity_meas_cluster_create(&humidity_meas_cfg),
ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
));
ESP_LOGI(TAG, "Humidity measurement cluster added");
esp_zb_pm2_5_measurement_cluster_cfg_t pm2_5_meas_cfg = {
.measured_value = 0xFFFF,
.min_measured_value = 0,
.max_measured_value = 65535,
};
ESP_ERROR_CHECK(esp_zb_cluster_list_add_pm2_5_measurement_cluster(
cluster_list,
esp_zb_pm2_5_measurement_cluster_create(&pm2_5_meas_cfg),
ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
));
ESP_LOGI(TAG, "PM2.5 measurement cluster added");
/* Code that makes it fail */
// esp_zb_carbon_dioxide_measurement_cluster_cfg_t co2_meas_cfg = {
// .measured_value = 0xFFFF,
// .min_measured_value = 0,
// .max_measured_value = 10000,
// };
// ESP_ERROR_CHECK(esp_zb_cluster_list_add_carbon_dioxide_measurement_cluster(
// cluster_list,
// esp_zb_carbon_dioxide_measurement_cluster_create(&co2_meas_cfg),
// ESP_ZB_ZCL_CLUSTER_SERVER_ROLE
// ));
// ESP_LOGI(TAG, "Carbon dioxide measurement cluster added");
return cluster_list;
}
static esp_zb_ep_list_t *custom_sensor_ep_create(uint8_t endpoint_id)
{
esp_zb_ep_list_t *ep_list = esp_zb_ep_list_create();
esp_zb_endpoint_config_t endpoint_config = {
.endpoint = endpoint_id,
.app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
.app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID,
.app_device_version = 0
};
esp_zb_ep_list_add_ep(ep_list, custom_sensor_clusters_create(), endpoint_config);
return ep_list;
}
static void configure_cluster_reporting(uint8_t endpoint, uint16_t cluster_id, uint16_t attr_id) {
esp_zb_zcl_reporting_info_t reporting_info = {
.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV,
.ep = endpoint,
.cluster_id = cluster_id,
.cluster_role = ESP_ZB_ZCL_CLUSTER_SERVER_ROLE,
.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID,
.u.send_info.min_interval = 1,
.u.send_info.max_interval = 0,
.u.send_info.def_min_interval = 1,
.u.send_info.def_max_interval = 0,
.u.send_info.delta.u16 = 10,
.attr_id = attr_id,
.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC,
};
esp_zb_zcl_update_reporting_info(&reporting_info);
}
static void init_zigbee(void)
{
esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG();
esp_zb_init(&zb_nwk_cfg);
esp_zb_ep_list_t *esp_zb_sensor_ep = custom_sensor_ep_create(HA_ESP_SENSOR_ENDPOINT);
esp_zb_device_register(esp_zb_sensor_ep);
configure_cluster_reporting(
HA_ESP_SENSOR_ENDPOINT,
ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT,
ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID
);
configure_cluster_reporting(
HA_ESP_SENSOR_ENDPOINT,
ESP_ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT,
ESP_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID
);
// configure_cluster_reporting(
// HA_ESP_SENSOR_ENDPOINT,
// ESP_ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_MEASUREMENT,
// ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MEASURED_VALUE_ID
// );
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_ERROR_CHECK(esp_zb_start(false));
}
static void esp_zb_task(void *pvParameters)
{
esp_zb_stack_main_loop();
}
static void read_temperature_task(void *pvParameters)
{
while (1) {
esp_zb_lock_acquire(portMAX_DELAY);
int16_t temp_value = 4000;
ESP_LOGI(TAG, "Temperature: %d °C", temp_value);
reportValue(ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, &temp_value);
float_t ambient_humidity = 4000;
ESP_LOGI(TAG, "Humidity: %.2f %%", ambient_humidity / 100.0f);
reportValue(ESP_ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT, ESP_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID, &ambient_humidity);
float_t pm25_value = 100.0f;
ESP_LOGI(TAG, "PM2.5: %.1f µg/m³", pm25_value);
reportValue(ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT, ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MEASURED_VALUE_ID, &pm25_value);
float_t co2_value = 200.0f;
ESP_LOGI(TAG, "CO2: %.1f ppm", co2_value);
// reportValue(ESP_ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_MEASUREMENT, ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MEASURED_VALUE_ID, &co2_value);
esp_zb_lock_release();
vTaskDelay(pdMS_TO_TICKS(5000));
}
}
void app_main(void)
{
esp_zb_platform_config_t config = {
.radio_config = ESP_ZB_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_ZB_DEFAULT_HOST_CONFIG(),
};
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
init_zigbee();
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
xTaskCreate(read_temperature_task, "temp_reader", 16384, NULL, 4, NULL);
} This one works, but as soon as I remove the Thank you for your precious help ! |
Hi, The hardcoded implementation provides better insights into your project, but it works fine on my end. I copied it into the
I reviewed the code you provided, and its logic appears clear. I believe it should work well. Could you also try enlarging the |
Hi, Here's the full crashing log, with the .elf (inside a zip because of github constraints): Senesp98.zip
PS: I will give a try to v5.3.2 a bit later but compilation failed on first tries for some reasons. But as it works fine for you with v5.5 it would be great if we manage to debug this for the latest version ! |
Answers checklist.
IDF version.
v5.5-dev-847-gcb3ac7429c
esp-zigbee-lib version.
1.6.1
esp-zboss-lib version.
1.6.1
Espressif SoC revision.
ESP32-H2
What is the expected behavior?
Hi,
I currently have 2 clusters on my device (temperature and humidity) and I'm trying to add a new Carbon Dioxide one. But as soon as I add it, the device crashes with:
What is the actual behavior?
The device should not crash
Steps to reproduce.
Added a new cluster with:
Report value with
More Information.
Am I missing anything here ?
Thanks !
The text was updated successfully, but these errors were encountered: