Feature: move web page to server and code in api #23

Open
opened 2025-11-09 11:24:31 -05:00 by sickprodigy · 0 comments
Owner

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:

Large HTML Strings (~14KB each)
When generating a page, Python must:

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!

Multiple Objects in Memory:
Garbage Collection Not Aggressive Enough:
MicroPython's GC doesn't run automatically as often as CPython. You need to manually call gc.collect() frequently.

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.

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: Large HTML Strings (~14KB each) When generating a page, Python must: 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! Multiple Objects in Memory: Garbage Collection Not Aggressive Enough: MicroPython's GC doesn't run automatically as often as CPython. You need to manually call gc.collect() frequently. 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.
sickprodigy added the enhancement label 2025-11-10 14:00:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sickprodigy/Auto-Garden#23