Feature: move web page to server and code in api #23
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
So i'm thinkin soon i will run out of memory/ram. It would be light weight to just code in an api and have a server/pc link to the pi.
Will need to host html files on local computer/server in order to view web page configurations. It's just too much to put on a pico with 250kb of ram. 70kb to load current full application. Not quite sure how to break it down I just think python loads into memory/ram and then runs from there. Once i figure out the way around it could be less restrictive
Pico W Memory Specs:
RAM (SRAM):
Total: 264 KB (264,192 bytes)
Available for MicroPython: ~190-220 KB (rest used by system)
Your current usage: Generating 14KB HTML pages + all your code/objects
Flash Storage:
Total: 2 MB
Used for: MicroPython firmware (~1.4 MB) + your scripts + config files
Available: ~600 KB for your code
Why You're Running Out of RAM:
Load the entire HTML template
Format it with variables
Convert to bytes
Send chunks over socket
Problem: The string exists in memory 2-3 times during this process!
Memory Saving Solutions:
Immediate Fixes (Already Done):
✅ Added gc.collect() before page generation
✅ Minified HTML (removed whitespace)
Additional Optimizations Needed:
Web Server Optimization - Stream HTML Instead of Building Full String:
Reduce Config Storage:
Remove extra whitespace - saves a few bytes when loaded into RAM.
Quick Memory Check Command:
Add this to see what's using memory:
Bottom Line:
Pico W has ~220KB usable RAM, and you're:
Using ~100KB for code/objects
Using ~14KB for each HTML page generation
Leaving ~100KB free (barely enough)
Solutions in order of priority:
✅ Call gc.collect() more often (every 5 seconds)
Consider splitting settings into smaller pages (less HTML per page)
Use chunked transfer encoding for HTML (advanced)
Remove auto-refresh or increase to 60 seconds (less frequent page loads)
For now, the gc.collect() fix should hold, but if you add more features, you'll need chunked HTML streaming.