So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By quackmore
#94177
what should be the minimum heap to avoid any errors?


Hard to say, that depends on your application and on the sdk modules you are using

for your own code you can try to figure out a worst case

while for the sdk modules you can try to run different test scenarios and use esp_get_minimum_free_heap_size to verify what happens

that's what I do
User avatar
By Inq720
#94194
quackmore wrote:
what should be the minimum heap to avoid any errors?

Hard to say, that depends on your application and on the sdk modules you are using
for your own code you can try to figure out a worst case
while for the sdk modules you can try to run different test scenarios and use esp_get_minimum_free_heap_size to verify what happens
that's what I do


I agree with @quackmore that it is very dependent on your whole app. But I can give you one data-point... and by the time you average that with all the others, it won't be much use. :lol:

In InqPortal I've written my own web socket server. It uses heap memory for buffering messages. At anything under 10kB/sec, the buffer is near empty. The Espressif code underneath can shovel out the data very quickly. As I push it harder say... between 100kB to 200kB/second it grows and shrinks but rarely drops below about 20kB as see using system_get_free_heap_size(). This is with all five connections blowing out data as fast as possible on very strong (short range) connections and little WiFi noise around.

If I increase the range, or am in a more noisy environment (local library) contention gets worse and TCP starts ACK/NAKing and the buffer will spike doing resends. In initial development, I didn't control the maximum size of the buffer. I just checked the os_malloc() and if it failed, I'd throw away the user data. This was not good enough... it would always reboot soon afterward. So I added a floor... I wouldn't attempt any allocations if the heap was below 6kB. This also occasionally reset the device. It tells me that the Espressif layer also does its own heap buffering and it uses more than 6kB sometimes.

Conclusion I don't allocate below 10kB and I don't have any MPU resets.
User avatar
By Inq720
#94198 I didn't say it was a good data point. :D

FWIW - Espressif lower level stuff still has to happen, the RTOS just rides on top of the same guts used in the NoOS version. Just saying... WiFi whether web sockets or MQTT still has to happen and 6 KB wasn't enough room, yet 10 KB is. (in my case)