Closed aginbarus closed 4 years ago
I am not familiar with esp_now_send functions, but in the OnDataRecv callback you copy the received buffer to a struct with a String inside, which is not okay. The String is a dynamic type and needs to be constructed and next set with the right data. You cannot just use memcpy. I am not sure though if this is the cause of your problems, but you need to correct this anyway.
@Jeroen88 : Although it's definitely a bad practice, I think it may work here with strings up to 10 bytes. See https://github.com/esp8266/Arduino/blob/a70e834d1ea26316d28ae41b4623550d7b47ed34/cores/esp8266/WString.h#L289
Well maybe you are right, but in the trace I see several alloc functions, so your problem might have something to do with memory management.
I took a quick look at WString.h It might work if the string is in SSO mode at the sending and the receiving side and if indeed the string is small enough. I was not aware that String has several modes. But anyway, too many "mights" and "ifs" for a good program IMHO.
I think you should send a zero terminated string. If you want to receive the result in a String, have a char * pointer to the beginning and just construct it with String(pointer).
Again, I am not sure if this is the cause of your problems, but it is definitely worth a try.
@Jeroen88 's comment above about memcpy into a struct with a String is absolutely correct. String is a non-contiguous object with mem management (i. e. it has ptrs inside). You need to serialize/deserialize your messages. Closing due to user error.
Basic Infos
Platform
Settings in IDE
Problem Description
I'm new to programming stuff, sorry if the question is ridiculous When I received a data from another esp8266/32 device using wifi theres some error in the received data (and followed by headers like when esp reboot)
Exception (28): epc1=0x4021276d epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000544e depc=0x00000000
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3456, room 16 tail 0 chksum 0x84 csum 0x84 va5432625 ~ld
but when I sending data to other esp32, It works and read fine by the esp32. i've tried to decode the exepction
0x4020bc84: lwip_cyclic_timer at core/timeouts.c line 233 0x401008e7: free(void) at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 362 0x4020bc84: lwip_cyclic_timer at core/timeouts.c line 233 0x4020bc94: lwip_cyclic_timer at core/timeouts.c line 243 0x4020af91: memp_free at core/memp.c line 447 0x4020be2c: sys_check_timeouts at core/timeouts.c line 390 0x40100648: umm_free_core(void) at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 316 0x401008e7: free(void*) at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 362 0x40100b74: calloc(size_t, size_t) at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 820 0x40202808: __esp_yield() at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266/core_esp8266_features.h line 92 0x40202dbe: __delay(unsigned long) at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\core_esp8266_wiring.cpp line 54 0x402012f1: loop() at C:\Users\J\Documents\Arduino\Project\ESP8266\ESP8266_mtm/ESP8266_mtm.ino line 131 0x40202930: loop_wrapper() at C:\Users\J\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\core_esp8266_main.cpp line 197
MCVE Sketch
Debug Messages