Someday I had this idea: I will use this device as xmpp client!
We could communicate outside while in range, or inside over internet (for example from school to home)…
Pretty brilliant, I told myself… was satisfied and excited to code.
I included classic <WiFi.h>, <WiFiClient.h> and so on, then WiFi.mode(WIFI_STA); WiFi.begin... hit the upload button and…
No matter what I do and where I call this new WiFi code, it crashes. The memory is surely not full, as you can see, I used Serial.println(ESP.getFreeHeap());, we have plenty. I’ve got IP, no problem here.
So… where is the problem and why it crashes?
I want WiFi on my ESP32!
The memory on the Chatter is pretty stretched as it is, and the WiFi stack also needs quite a bit of memory to operate, so it isn’t unreasonable to assume there simply isn’t enough free memory to have both WiFi and the rest of the firmware.
Sure, ESP.getFreeHeap() says that there is enough total free memory on the heap, however, that memory is fragmented across several blocks, and when allocating memory (LVGL is trying to allocate 83.5kB in this case), you need a contiguous block of memory for the allocation to succeed. You can use ESP.getMaxAllocHeap() to get the largest free contiguous block of memory on the heap, i.e. the maximum amount of memory you can allocate with a single malloc. Here’s a good illustrated explanation of what memory fragmentation is: Memory Fragmentation, your worst nightmare | Software Verify
Memory fragmentation, in general, is a pretty complex issue to tackle. From the trace you posted, it seems like you used the WiFi stack, connected to an AP, got an IP successfully, but now because of the WiFi stack, LVGL (the UI library) can’t allocate the memory it needs. I can’t pinpoint in which part of the code that particular allocation happens, but if it’s some less-used part of the software, maybe you could exclude that feature or optimize it so it needs less memory.
FSLVGL::loadCache(); loads the images used in the UI from the flash into the RAM. Since accessing data from the flash can be quite slow, especially for images and animations, loading them into RAM speeds up the whole UI by a lot.
If you wish, you can completely omit that line and everything will keep working as before, although you will see some stuttering in the UI.
You were right, it is working without that loadCache(). Thanks to additional available memory I have usable WiFi now. But as you mentioned, the experience in UI is really bad, almost no animation and A LOT OF stuttering. So now it’s about compromise. Although I appreciate nice animated GUI (which I expect is primarily targeted for kids to be attractive), I am practical person and do not need any fancy stuff, so maybe I will learn how to use LVGL and simplify things to bare minimum, which then will fit into the cache.
It’s pretty complex, though. Many screens and classes… I’d like to code in Platformio, but have some troubles with setting up the project and all dependencies. Is there any guide specific for Platformio and Chatter 2?
Regarding Platformio, we only have guides for Nibble, JayD, Spencer, and Ringo. Unfortunately, we won’t be making new PlatformIO packages in the near future.