Buffer/Memory issue with Websockets and ESP32-Cam

cgmckeever
Posts: 1
Joined: Thu Aug 06, 2020 3:08 pm

Buffer/Memory issue with Websockets and ESP32-Cam

Postby cgmckeever » Thu Aug 06, 2020 3:49 pm

GitHub Issue

https://github.com/me-no-dev/ESPAsyncWe ... issues/820

Im trying to stream ESP32 -Cam data via Websockets (AsyncWebSocket) , and after a couple seconds device crashes and reboots. Its clear Im overflowing it, but I havent figured a way to manage this better. I put it in a timer (to reduce frequency), and it still crashes - pretty much the same.

Am I overlooking a way to wait for the sends to finish and/or do some memory clean up?

Thanks!

Code: Select all

abort() was called at PC 0x4016063b on core 0 

Code: Select all

AsyncWebSocket webSocket("/ws");
camera_fb_t *fb = NULL;  

...  

void loop() {    
  fb = esp_camera_fb_get();    
  webSocket.binaryAll(fb->buf, fb->len);    
  esp_camera_fb_return(fb); 
}

un0038998
Posts: 1
Joined: Sun Sep 12, 2021 5:54 pm

Re: Buffer/Memory issue with Websockets and ESP32-Cam

Postby un0038998 » Sun Sep 12, 2021 5:57 pm

I faced the similar issues with AsyncWebSocket when sending huge data continuously .
I was sending binary image from esp32 cam board and each image was 5Kb .
So when we keep sending messages , the queue gets full if connection is slow or receiver is slow.
Then It consumes whole heap memory available for esp32 board (max heap available around 180kb) .
So I changed the WS_MAX_QUEUED_MESSAGES parameter to 15 from 32. So the max messages queued will have the total size of 15*5kb = 75kb which is much less than total heap .
It resolved the issue for me and it never crashed again .
You can change this setting in AsyncWebSocket.H file in the library folder.

Check the size of the messages you are sending and set this parameter accordingly so that it will never exceed total heap size.
Hope this might help.

Who is online

Users browsing this forum: Google [Bot] and 105 guests