Replies: 3 comments 6 replies
-
Flash memory is not the same as RAM. Since the web page is already in flash memory, it doesn't seem like putting another copy there would be very useful. If _cached_web_page = None
def web_page():
global _cached_web_page
if _cached_web_page is None:
data = bytearray(27440)
esp.flash_read(0x250000, data)
_cached_web_page = data.decode('utf-8')
return _cached_web_page Or, if you don't actually need the entire web page in RAM at one time, e.g. you are writing it to a network stream, you could read from flash in smaller chunks. |
Beta Was this translation helpful? Give feedback.
-
As @dlech said, read the 27kb in smaller segments of, for example 1kb, and send those 1kb segments. That way you will need at most 1kb of RAM and it will at most be a bit slower. |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, the ESP32 Lolin is sending the page. In that case, you could use a web server such as microdot or tinyweb, both have the capability to send data in chunks to avoid allocating a large buffer. Are you also receiving the html page on another ESP32? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am currently having problems with creating a bytearray and "unable to allocate memory error"
I am using an ESP32 Lolin lite with 4Mb of Flash memory - I have a 27Kb of HTML stored in the external flash memomry at 0x250000 which I can read back using the esp.flash_read() function without any problems and view the webpage on another device when esp32 is set up as an access point.
My problem comes when I incorporate this in my main script - I then run into problems with not being able to allocate the 27Kb due to not enough memory - although I have enough in the external flash, but guessing when I create a bytearray it doesn't get created in the external flash?
Is there a way of creating the bytearray in the flash - for example at address 0x300000 which I know is available and not being used?
'def web_page():
data = bytearray(27440)
page = esp.flash_read(0x250000, data)
page = data.decode('utf-8')
#print(page)
return page'
Many thanks
Beta Was this translation helpful? Give feedback.
All reactions