-
Hello, I developed a device authorization app for my esp32-c3 with esp-mbedtls: https://github.com/burumdev/esp32-padlock The problem is currently I can only run one embassy task in task pool due to memory overflows. And available memory for other tasks is rather limited at this point. If I use mbedtls from IDF, will I be able to better fit this authorization section to an app that can actually do other things? I'm aware of #75 and it could help a bit. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
In short, no. a) "mbedtls from IDF" is not "in ROM" |
Beta Was this translation helpful? Give feedback.
-
Here is my experience: Every TLS session takes about 40kb-45kb, esp-wifi takes around 50kb-60kb. This piles up pretty quickly and memory is exhausted very fast. If you can switch to esp32-s3, you can use PSRAM for most things. ESP-WIFI will always need the internal RAM, and so does the stack. TLS for now require internal RAM but could move to PSRAM in the future and all the rest I push to the heap in PSRAM. So eventually the major internal memory bottleneck is esp-mbedtls with the large memory need for TLS sessions in the internal RAM, but I hope it will be resolved in the future and would allow using PSRAM for that as well. |
Beta Was this translation helpful? Give feedback.
-
BTW (not related to the question) - for user facing server side using TLS with embedded device is less useful IMO because its always self signed certificates and user is warned in the browser about insecure app, and switch to advanced, accept risks, etc. a reall bad user experience, and such a pain that I'm not sure it is that useful anyway. |
Beta Was this translation helpful? Give feedback.
-
Your server task could be optimized. I suggest using something like edge-http for multiple handlers, which would reduce the memory ballooning of spawning multiple times the same server task, and only "duplicate" the required resources to serve multiple clients. Your server task loads a copy of your certificates per instance, while using edge-http, you'd only need to load it once. Etc. I know that the C3 is more memory contrained, but you should be able to support 2 handlers at least. As for flash usage, your HTML could be optimized, if you use something like https://github.com/wilsonzlin/minify-html/ in your This is a bit hacky, but you could do something like: // Inject extra data as json in the HTML page
connection.write_all(b"<script type=\"application/json\" id=\"unlock-state\">").await?;
connection.write_all(&buffer[..len]).await?;
connection.write_all(b"</script>\n").await?;
connection
.write_all(include_bytes!('your-webpage.html')) And then in your HTML do: <script>
const data = JSON.parse(document.getElementById("unlock-state").textContent);
</script> To fetch computed injected data |
Beta Was this translation helpful? Give feedback.
Here is my experience:
Every TLS session takes about 40kb-45kb, esp-wifi takes around 50kb-60kb.
Add to that the various buffers used in every web task.
Embassy tasks could also take a significant memory for the tasks (which can be to some extent optimized but not a lot).
Also need enough space for the stack.
etc.
This piles up pretty quickly and memory is exhausted very fast.
If you can switch to esp32-s3, you can use PSRAM for most things. ESP-WIFI will always need the internal RAM, and so does the stack. TLS for now require internal RAM but could move to PSRAM in the future and all the rest I push to the heap in PSRAM.
So eventually the major internal memory bottleneck is esp-mbedtls w…