Skip to content
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

How can I send data of type int32 or larger from esp32-h2 module to another esp32-he module (TZ-1344) #495

Open
mehmetbozhaydar opened this issue Nov 28, 2024 · 2 comments
Labels

Comments

@mehmetbozhaydar
Copy link

Question

I am new to esp-idf. Which library should I use to send int32 type data with Zigbee?

Additional context.

No response

@github-actions github-actions bot changed the title How can I send data of type int32 or larger from esp32-h2 module to another esp32-he module How can I send data of type int32 or larger from esp32-h2 module to another esp32-he module (TZ-1344) Nov 28, 2024
@xieqinan
Copy link
Contributor

Yes, if you expect to use the Zigbee to achieve your purpose, I think you can refer to the docs first.

@mehmetbozhaydar
Copy link
Author

mehmetbozhaydar commented Nov 30, 2024

@xieqinan
roblem : I am trying to implement Zigbee communication between two ESP32-H2 modules, with the aim of sending and receiving int32 data. However, I am encountering a Guru Meditation Error: Core 0 panic'ed (Load access fault) when attempting to initialize my Zigbee device and register the custom cluster with a 32-bit integer attribute.

This error seems to be related to memory access issues when attempting to create and register a custom cluster, and I'm unsure of the root cause. The error occurs after initializing the Zigbee stack and registering the device with a custom attribute for sending an int32 value.

Error Details: When I run my application, I receive the following error message:

` I (392) app_start: Starting scheduler on CPU0
I (397) main_task: Started on CPU0
I (397) main_task: Calling app_main()
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.

Core 0 register dump:
MEPC : 0x42012cde RA : 0x420120e2 SP : 0x40810e90 GP : 0x4080a410
--- 0x42012cde: zb_bufpool_storage_allocate at ??:?
0x420120e2: allocate_buffer_unsafe at zb_bufpool_mult.c.obj:?

TP : 0x40805828 T0 : 0x4000af8c T1 : 0xffffffe0 T2 : 0x00010401
--- 0x40805828: xQueueReceiveFromISR at C:/Users/Haydar/Documents/esp/v5.1/esp-idf/components/freertos/FreeRTOS-Kernel/queue.c:2182
0x4000af8c: multi_heap_internal_unlock in ROM

S0/FP : 0x00000001 S1 : 0x4080be20 A0 : 0x00000000 A1 : 0x00000050
A2 : 0x4080be20 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000001 A7 : 0x00000002 S2 : 0x00000000 S3 : 0x40810ef8
S4 : 0x00000000 S5 : 0x00000000 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x00000000 T4 : 0x00000001 T5 : 0x4084dc98 T6 : 0x00000000
MSTATUS : 0x00001881 MTVEC : 0x40800001 MCAUSE : 0x00000005 MTVAL : 0x00000000
--- 0x40800001: _vector_table at ??:?

MHARTID : 0x00000000

Stack memory:
40810e90: 0x00000040 0x4084dc54 0x00000001 0x420120e2 0x4084dcf0 0x4084dc6c 0x00000000 0x40810ef8
--- 0x420120e2: allocate_buffer_unsafe at zb_bufpool_mult.c.obj:?

40810eb0: 0x00000000 0x00000000 0x40810ef8 0x42012176 0x4084daa8 0x0000ffff 0x4201b650 0x420121ce
--- 0x42012176: process_delayed_buf_entry_unsafe at zb_bufpool_mult.c.obj:?
0x4201b650: zb_zcl_init_periodic_activities at zcl_common.c.obj:?
0x420121ce: zb_get_buf_delayed at zb_bufpool_mult.c.obj:?

40810ed0: 0x00030003 0x4084dcf0 0x40840003 0x00000000 0x00000000 0x4080e000 0x4201b650 0x420122d0
--- 0x4201b650: zb_zcl_init_periodic_activities at zcl_common.c.obj:?
0x420122d0: zb_buf_get_out_delayed_func at ??:?

40810ef0: 0x00000000 0x00000000 0x4201b650 0x00010000 0x00000000 0x00000000 0x4084dca8 0x42021012
--- 0x4201b650: zb_zcl_init_periodic_activities at zcl_common.c.obj:?
0x42021012: zb_af_register_device_ctx at ??:?

40810f10: 0x00000000 0x4080e000 0x4084dca8 0x4200a51e 0x00000000 0x00000000 0x00000000 0x00000000
--- 0x4200a51e: esp_zb_device_register at ??:?

40810f30: 0x00000000 0x4080e000 0x4080e000 0x42008e06 0x00000000 0x0001e240 0xf2010401 0x000000ff
--- 0x42008e06: app_main at C:/Users/Haydar/Music/HA_on_off_light/main/server.c:142

40810f50: 0x42043218 0x00000000 0x42043000 0x420392e2 0x00000000 0x00001388 0x00000001 0x00000000
--- 0x420392e2: main_task at C:/Users/Haydar/Documents/esp/v5.1/esp-idf/components/freertos/app_startup.c:209 (discriminator 13)

40810f70: 0x00000000 0x00000000 0x00000000 0x40806e10 0x00000000 0x00000000 0x00000000 0x00000000
--- 0x40806e10: vPortTaskWrapper at C:/Users/Haydar/Documents/esp/v5.1/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:205

40810f90: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
40810fb0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000154 0x40810f10 0x4080e124 0x4080b360 0x4080b360
40810fd0: 0x40810fc0 0x4080b358 0x00000018 0xfdbf57db 0xd1b2afd8 0x40810fc0 0x00000000 0x00000001
40810ff0: 0x4080ffbc 0x6e69616d 0xf5f9f100 0x7fbffaab 0x001a007f 0x00000000 0x40810fb0 0x00000001
40811010: 0x00000000 0x00000000 0x00000000 0x00000000 0x4080eac4 0x4080eb2c 0x4080eb94 0x00000000
40811030: 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x40011484 0x00000000 0x00000000
--- 0x40011484: _cleanup_r in ROM

40811050: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40811070: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40811090: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408110b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408110d0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408110f0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40811110: 0x40000000 0x00000600 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
--- 0x40000000: _start in ROM `
Problem: The device crashes with a Guru Meditation Error when attempting to start Zigbee commissioning and register the custom cluster with the int32 attribute. The error indicates an issue with memory access when handling the custom cluster.

Steps Taken:
I’ve checked the code for proper initialization of the endpoint list, cluster list, and custom cluster.
I have used a static value (123456) for the int32 attribute.
I’ve attempted to add basic clusters (like Basic and Identify) alongside my custom cluster.

Additional Context:
I am using ESP-IDF v5..5 for development.
The error occurs consistently during the initialization phase when the Zigbee stack is being set up.
I am able to initialize Zigbee without the custom cluster but encounter the panic when adding it.

Request:
Has anyone encountered this issue before with Zigbee on ESP32-H2 modules?
Any suggestions on how to resolve the Load access fault error, or any insights on proper memory handling when working with custom clusters in Zigbee?

System Info:
ESP32-H2 (both modules)
ESP-IDF v5.1.5

My code

`#include "esp_log.h"
#include "string.h"
#include "esp_check.h"
#include "esp_zigbee_core.h"
#include "esp_zigbee_cluster.h"
#include "esp_zigbee_type.h"
#include "esp_zigbee_attribute.h"
#include "esp_zigbee_endpoint.h"

#define CUSTOM_SERVER_ENDPOINT 0x01
#define CUSTOM_CLUSTER_ID 0xFF00
#define CUSTOM_ATTR_INT32_ID 0x0000
#define TAG "CUSTOM_SERVER"

// Endpoint list initialization
static esp_zb_ep_list_t *ep_list = NULL;
static esp_zb_cluster_list_t *cluster_list = NULL;
static esp_zb_attribute_list_t *custom_cluster = NULL;

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");
}

// Function prototypes
static esp_err_t zb_custom_request_handler(const esp_zb_zcl_custom_cluster_command_message_t *message);
static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message);

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;
esp_zb_zdo_signal_device_annce_params_t *dev_annce_params = NULL;

switch (sig_type) {
case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP:
ESP_LOGI(TAG, "Initializing 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 formation");
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_FORMATION);
} else {
esp_zb_bdb_open_network(180);
ESP_LOGI(TAG, "Device rebooted");
}
} else {
ESP_LOGE(TAG, "Failed to initialize Zigbee stack (status: %s)", esp_err_to_name(err_status));
}
break;
case ESP_ZB_BDB_SIGNAL_FORMATION:
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, "Formed 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());
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
} else {
ESP_LOGI(TAG, "Restart network formation (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_FORMATION, 1000);
}
break;
case ESP_ZB_BDB_SIGNAL_STEERING:
if (err_status == ESP_OK) {
ESP_LOGI(TAG, "Network steering started");
}
break;
case ESP_ZB_ZDO_SIGNAL_DEVICE_ANNCE:
dev_annce_params = (esp_zb_zdo_signal_device_annce_params_t )esp_zb_app_signal_get_params(p_sg_p);
ESP_LOGI(TAG, "New device commissioned or rejoined (short: 0x%04hx)", dev_annce_params->device_short_addr);
break;
case ESP_ZB_NWK_SIGNAL_PERMIT_JOIN_STATUS:
if (err_status == ESP_OK) {
if (
(uint8_t *)esp_zb_app_signal_get_params(p_sg_p)) {
ESP_LOGI(TAG, "Network(0x%04hx) is open for %d seconds", esp_zb_get_pan_id(), *(uint8_t *)esp_zb_app_signal_get_params(p_sg_p));
} else {
ESP_LOGW(TAG, "Network(0x%04hx) closed, devices joining not allowed.", esp_zb_get_pan_id());
}
}
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;
}

}

void app_main() {
// Create endpoint list
ep_list = esp_zb_ep_list_create();
if (ep_list == NULL) {
ESP_LOGE(TAG, "Failed to create endpoint list.");
return;
}

// Configure endpoint
esp_zb_endpoint_config_t endpoint_config = {
.endpoint = CUSTOM_SERVER_ENDPOINT,
.app_profile_id = ESP_ZB_AF_HA_PROFILE_ID,
.app_device_id = ESP_ZB_HA_CUSTOM_ATTR_DEVICE_ID,
.app_device_version = 0,
};

// Create cluster list
cluster_list = esp_zb_zcl_cluster_list_create();
if (cluster_list == NULL) {
ESP_LOGE(TAG, "Failed to create cluster list.");
return;
}

// Create custom cluster
custom_cluster = esp_zb_zcl_attr_list_create(CUSTOM_CLUSTER_ID);
if (custom_cluster == NULL) {
ESP_LOGE(TAG, "Failed to create custom cluster.");
return;
}

// Add int32 attribute
uint32_t custom_attr_value = 123456; // Example starting value
esp_zb_custom_cluster_add_custom_attr(custom_cluster, CUSTOM_ATTR_INT32_ID, ESP_ZB_ZCL_ATTR_TYPE_U32,
ESP_ZB_ZCL_ATTR_ACCESS_READ_WRITE, &custom_attr_value);

// Add other necessary clusters (e.g., Basic, Identify)
esp_zb_cluster_list_add_basic_cluster(cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_identify_cluster(cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);

// Add custom cluster
esp_zb_cluster_list_add_custom_cluster(cluster_list, custom_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);

// Add to endpoint list
esp_zb_ep_list_add_ep(ep_list, cluster_list, endpoint_config);

// Register Zigbee device
esp_zb_device_register(ep_list);

// Register action handler
esp_zb_core_action_handler_register(zb_action_handler);

ESP_LOGI(TAG, "Zigbee device successfully registered.");

}

// Custom request handler
static esp_err_t zb_custom_request_handler(const esp_zb_zcl_custom_cluster_command_message_t *message) {
ESP_LOGI(TAG, "Received custom command");
ESP_LOGI(TAG, "Payload size: %d", message->data.size);

if (message->data.size == sizeof(uint32_t)) {
uint32_t received_value;
memcpy(&received_value, message->data.value, sizeof(uint32_t));
ESP_LOGI(TAG, "Received int32 value: %ld", received_value);
}
return ESP_OK;

}

// General action handler
static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) {
switch (callback_id) {
case ESP_ZB_CORE_CMD_CUSTOM_CLUSTER_REQ_CB_ID:
return zb_custom_request_handler((esp_zb_zcl_custom_cluster_command_message_t *)message);
default:
ESP_LOGW(TAG, "Unhandled callback ID: 0x%x", callback_id);
return ESP_OK;
}
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants