cJSON object with esp_event_post triggers Guru Meditation Error
Posted: Wed Sep 13, 2023 10:45 am
Hello! I work with an event model and transmit various data via esp_event_post
Firstly, I read ADC4 NTC value
What I am doing coding:
ntc.c component
rest_server.c component
handler:
And when I try to pass cJSON to event_data, I got the error
This problem occurs only when reading the structure of cJSON in adc_got_temp_event_handler. If I pass number (not cJSON) it works fine.
I need to pass not a single number, but a more complex structure with key-value pairs. What was I wrong about?
Firstly, I read ADC4 NTC value
- ESP_LOGW(NTC_TAG, "ADC Value: %d, Temp Value: %.1f", adc_raw[0][0], celsius);
ntc.c component
- ESP_LOGW(NTC_TAG, "ADC Value: %d, Temp Value: %.1f", adc_raw[0][0], celsius);
- cJSON *json = cJSON_CreateObject();
- cJSON_AddNumberToObject(json, "test", 1234);
- esp_err_t err = esp_event_post(APP_EVENTS, S_ADC_GOT_TEMP, &json, sizeof(json), portMAX_DELAY);
- esp_err_t err = esp_event_handler_register(APP_EVENTS, S_ADC_GOT_TEMP, &adc_got_temp_event_handler, NULL);
- static void adc_got_temp_event_handler(
- void *arg,
- esp_event_base_t event_base,
- int32_t event_id, void *adc_data)
- {
- const cJSON *json_data = adc_data;
- ESP_LOGI(REST_TAG, "%s", cJSON_Print(json_data));
- //OR
- int temp = cJSON_GetObjectItem(json, "test")->valueint;
- ESP_LOGW(REST_TAG, "%d", temp);
- }
- Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
- Core 0 register dump:
- PC : 0x400014fd PS : 0x00060b30 A0 : 0x8015e8a2 A1 : 0x3ffbb450
- 0x400014fd: strlen in ROM
- A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0000ff00
- A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x00000000
- A10 : 0x00000000 A11 : 0x00000008 A12 : 0x3ffbb694 A13 : 0x00000000
- A14 : 0x3ffbb664 A15 : 0x00000001 SAR : 0x00000004 EXCCAUSE: 0x0000001c
- EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
- 0x400014fd: strlen in ROM
- 0x4000150d: strlen in ROM
- Backtrace: 0x400014fa:0x3ffbb450 0x4015e89f:0x3ffbb460 0x4015ff49:0x3ffbb780 0x4016edc9:0x3ffbb7b0 0x40090199:0x3ffbb7e0 0x400d8571:0x3ffbb830 0x4016d9c1:0x3ffbb850 0x4016d4f7:0x3ffbb880 0x4016d5ad:0x3ffbb8c0 0x4008c715:0x3ffbb8e0
- 0x400014fa: strlen in ROM
I need to pass not a single number, but a more complex structure with key-value pairs. What was I wrong about?