Page 1 of 1

WiFi module heap usage

Posted: Fri May 07, 2021 9:31 pm
by pscsuk
(ESP32 WROOM 32)

I'm struggling with running out of heap RAM on a program I'm developing. It needs BluetoothSerial and BLE, and WiFi is a 'nice to have' (for getting the time using NTP and retrieving logs).

But, if I include all 3 libraries it keeps crashing or hanging because of lack of heap space.

The WiFi module uses about 80kB as soon as it is initialised. Is there any nice way of reducing this?

From a bit of diagnosis, the esp_wifi_init() call in WiFiGeneric.cpp seems to be where the majority of the memory is used. It appears that I could change the config being passed to this call to reduce the number of buffers being allocated. Is there any guide on minimum values for these? (would '1' work?). The WiFi functionality required is minimal, so speed isn't important, and the documentation seems to suggest that high buffers = high speed, so reducing them sounds like it may be a plan.

However, the WiFiGeneric.cpp doesn't seem to have any way of modifying the structure being passed to esp_wifi_init(), so I guess I'll have to either hack the library or copy it and hack my copy of it.

Am I right in my plan to reduce the number of buffers to reduce the heap usage, and is there a better way to do this that I've missed?