ESP32 Crashing sometimes crashes when sending a Websocket

I’m having trouble with my ESP32-S2 sometimes (seemingly randomly?) crashing when sending a large websocket.

The crash log outputted on serial:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x40087297 PS : 0x00060830 A0 : 0x80087bc9 A1 : 0x3ffd2560
A2 : 0x3ffc655c A3 : 0x3ffe3610 A4 : 0x3ffcbd54 A5 : 0x3ffc65d8
A6 : 0x3f4c0058 A7 : 0x00000001 A8 : 0xa941d536 A9 : 0x3ffd2540
A10 : 0x3ffe3610 A11 : 0x3ffe3610 A12 : 0x3ffe35f0 A13 : 0x00000000
A14 : 0x3ffcd288 A15 : 0x3ffcd23c SAR : 0x00000013 EXCCAUSE: 0x0000001c
EXCVADDR: 0xa941d542 LBEG : 0x3ffe35f0 LEND : 0x00000000 LCOUNT : 0x40028358
Backtrace:0x40087294:0x3ffd25600x40087bc6:0x3ffd2590 0x40087bdf:0x3ffd25b0 0x40087bed:0x3ffd25d0 0x40083d30:0x3ffd25f0 0x40083d4f:0x3ffd2610 0x401015dd:0x3ffd2630 0x4008dc95:0x3ffd2650 0x40083366:0x3ffd2670 0x400918a1:0x3ffd2690
#0 0x40087294:0x3ffd2560 in AsyncWebSocket::_cleanBuffers() at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:1224 (discriminator 3)
#1 0x40087bc6:0x3ffd2590 in AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer*) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:986
#2 0x40087bdf:0x3ffd25b0 in AsyncWebSocket::binaryAll(char const*, unsigned int) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:974
#3 0x40087bed:0x3ffd25d0 in AsyncWebSocket::binaryAll(unsigned char*, unsigned int) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:1133
#4 0x40083d30:0x3ffd25f0 in sendMeasurements_Bin() at src/websockets.cpp:71
#5 0x40083d4f:0x3ffd2610 in captureMeasurements() at src/websockets.cpp:49
#6 0x401015dd:0x3ffd2630 in std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) at c:usersvojta.platformiopackagestoolchain-xtensa-esp32s2xtensa-esp32s2-elfincludec++8.4.0bits/std_function.h:297
#7 0x4008dc95:0x3ffd2650 in std::function<void ()>::operator()() const at c:usersvojta.platformiopackagestoolchain-xtensa-esp32s2xtensa-esp32s2-elfincludec++8.4.0bits/std_function.h:687
(inlined by) Ticker::update() at .pio/libdeps/esp32-s2-saola-1/Ticker/Ticker.cpp:72
#8 0x40083366:0x3ffd2670 in loop() at src/main.cpp:134
#9 0x400918a1:0x3ffd2690 in loopTask(void*) at C:/Users/vojta/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50
ELF file SHA256: 0000000000000000
</code>
<code>Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled. Core 0 register dump: PC : 0x40087297 PS : 0x00060830 A0 : 0x80087bc9 A1 : 0x3ffd2560 A2 : 0x3ffc655c A3 : 0x3ffe3610 A4 : 0x3ffcbd54 A5 : 0x3ffc65d8 A6 : 0x3f4c0058 A7 : 0x00000001 A8 : 0xa941d536 A9 : 0x3ffd2540 A10 : 0x3ffe3610 A11 : 0x3ffe3610 A12 : 0x3ffe35f0 A13 : 0x00000000 A14 : 0x3ffcd288 A15 : 0x3ffcd23c SAR : 0x00000013 EXCCAUSE: 0x0000001c EXCVADDR: 0xa941d542 LBEG : 0x3ffe35f0 LEND : 0x00000000 LCOUNT : 0x40028358 Backtrace:0x40087294:0x3ffd25600x40087bc6:0x3ffd2590 0x40087bdf:0x3ffd25b0 0x40087bed:0x3ffd25d0 0x40083d30:0x3ffd25f0 0x40083d4f:0x3ffd2610 0x401015dd:0x3ffd2630 0x4008dc95:0x3ffd2650 0x40083366:0x3ffd2670 0x400918a1:0x3ffd2690 #0 0x40087294:0x3ffd2560 in AsyncWebSocket::_cleanBuffers() at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:1224 (discriminator 3) #1 0x40087bc6:0x3ffd2590 in AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer*) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:986 #2 0x40087bdf:0x3ffd25b0 in AsyncWebSocket::binaryAll(char const*, unsigned int) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:974 #3 0x40087bed:0x3ffd25d0 in AsyncWebSocket::binaryAll(unsigned char*, unsigned int) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:1133 #4 0x40083d30:0x3ffd25f0 in sendMeasurements_Bin() at src/websockets.cpp:71 #5 0x40083d4f:0x3ffd2610 in captureMeasurements() at src/websockets.cpp:49 #6 0x401015dd:0x3ffd2630 in std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) at c:usersvojta.platformiopackagestoolchain-xtensa-esp32s2xtensa-esp32s2-elfincludec++8.4.0bits/std_function.h:297 #7 0x4008dc95:0x3ffd2650 in std::function<void ()>::operator()() const at c:usersvojta.platformiopackagestoolchain-xtensa-esp32s2xtensa-esp32s2-elfincludec++8.4.0bits/std_function.h:687 (inlined by) Ticker::update() at .pio/libdeps/esp32-s2-saola-1/Ticker/Ticker.cpp:72 #8 0x40083366:0x3ffd2670 in loop() at src/main.cpp:134 #9 0x400918a1:0x3ffd2690 in loopTask(void*) at C:/Users/vojta/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50 ELF file SHA256: 0000000000000000 </code>
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40087297  PS      : 0x00060830  A0      : 0x80087bc9  A1      : 0x3ffd2560  
A2      : 0x3ffc655c  A3      : 0x3ffe3610  A4      : 0x3ffcbd54  A5      : 0x3ffc65d8
A6      : 0x3f4c0058  A7      : 0x00000001  A8      : 0xa941d536  A9      : 0x3ffd2540  
A10     : 0x3ffe3610  A11     : 0x3ffe3610  A12     : 0x3ffe35f0  A13     : 0x00000000
A14     : 0x3ffcd288  A15     : 0x3ffcd23c  SAR     : 0x00000013  EXCCAUSE: 0x0000001c  
EXCVADDR: 0xa941d542  LBEG    : 0x3ffe35f0  LEND    : 0x00000000  LCOUNT  : 0x40028358


Backtrace:0x40087294:0x3ffd25600x40087bc6:0x3ffd2590 0x40087bdf:0x3ffd25b0 0x40087bed:0x3ffd25d0 0x40083d30:0x3ffd25f0 0x40083d4f:0x3ffd2610 0x401015dd:0x3ffd2630 0x4008dc95:0x3ffd2650 0x40083366:0x3ffd2670 0x400918a1:0x3ffd2690 

  #0  0x40087294:0x3ffd2560 in AsyncWebSocket::_cleanBuffers() at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:1224 (discriminator 3)
  #1  0x40087bc6:0x3ffd2590 in AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer*) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:986
  #2  0x40087bdf:0x3ffd25b0 in AsyncWebSocket::binaryAll(char const*, unsigned int) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:974
  #3  0x40087bed:0x3ffd25d0 in AsyncWebSocket::binaryAll(unsigned char*, unsigned int) at .pio/libdeps/esp32-s2-saola-1/ESP Async WebServer/src/AsyncWebSocket.cpp:1133
  #4  0x40083d30:0x3ffd25f0 in sendMeasurements_Bin() at src/websockets.cpp:71
  #5  0x40083d4f:0x3ffd2610 in captureMeasurements() at src/websockets.cpp:49
  #6  0x401015dd:0x3ffd2630 in std::_Function_handler<void (), void (*)()>::_M_invoke(std::_Any_data const&) at c:usersvojta.platformiopackagestoolchain-xtensa-esp32s2xtensa-esp32s2-elfincludec++8.4.0bits/std_function.h:297
  #7  0x4008dc95:0x3ffd2650 in std::function<void ()>::operator()() const at c:usersvojta.platformiopackagestoolchain-xtensa-esp32s2xtensa-esp32s2-elfincludec++8.4.0bits/std_function.h:687
      (inlined by) Ticker::update() at .pio/libdeps/esp32-s2-saola-1/Ticker/Ticker.cpp:72
  #8  0x40083366:0x3ffd2670 in loop() at src/main.cpp:134
  #9  0x400918a1:0x3ffd2690 in loopTask(void*) at C:/Users/vojta/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50




ELF file SHA256: 0000000000000000

The function that periodically sends the websockets:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>void sendMeasurements_Bin(){
Serial.print("sending----");
ws.binaryAll((uint8_t*)buffer, sizeof(buffer));
Serial.println("sent");
return ;
}
</code>
<code>void sendMeasurements_Bin(){ Serial.print("sending----"); ws.binaryAll((uint8_t*)buffer, sizeof(buffer)); Serial.println("sent"); return ; } </code>
void sendMeasurements_Bin(){
  Serial.print("sending----");
  ws.binaryAll((uint8_t*)buffer, sizeof(buffer));
  Serial.println("sent");
  return ;

}

Where buffer is an array of structs:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>struct __attribute__((packed)) Measurement {
int16_t current_L;
int16_t current_R;
int16_t current_Total;
int16_t setpoint;
int16_t error;
uint32_t encoder_L;
uint32_t encoder_R;
uint32_t timestamp; // Store the time when the measurement was taken
};
const int BUFFER_SIZE = 100;
Measurement buffer[BUFFER_SIZE];
</code>
<code>struct __attribute__((packed)) Measurement { int16_t current_L; int16_t current_R; int16_t current_Total; int16_t setpoint; int16_t error; uint32_t encoder_L; uint32_t encoder_R; uint32_t timestamp; // Store the time when the measurement was taken }; const int BUFFER_SIZE = 100; Measurement buffer[BUFFER_SIZE]; </code>
struct __attribute__((packed)) Measurement {
    int16_t current_L;
    int16_t current_R;
    int16_t current_Total;
    int16_t setpoint;
    int16_t error;
    uint32_t encoder_L;
    uint32_t encoder_R;
    uint32_t timestamp; // Store the time when the measurement was taken
};

const int BUFFER_SIZE = 100;

Measurement buffer[BUFFER_SIZE];

Do you know what could be causing this issue? My guess is it’s something memory related but that doesn’t make sense to me as there’s no new memory being allocated, the buffer is initialized only once and then its rewritten and sent.

I tried printing out free heap size every time the data is sent, using:

Serial.print(esp_get_free_heap_size());

The free heap size doesn’t change very much, which is expected.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật