Flash storage Module, any js type , web pages, css, js and images #6060
Replies: 1 comment
-
Posted at 2016-03-05 by Wilberforce Complex types can be stored, they are automatically converted to JSON strings and back again:
Posted at 2016-03-05 by Wilberforce web assets can be stored:
I'll post a demo tomorrow on how to serve these in a web server, using the Posted at 2016-03-05 by @allObjects Excellent! - Very very cool... What about delete? ...and garbage collect? - see memory manager... just dealing with strings... so far cross developed in HTML5 with test bed a while ago... having reference objects so they would not eat up the RAM... and keying was next on my list... are next on list. Unfortunately I'm too busy with other stuff and laying low, Espruino-wise... :( ...the more I enjoy what you present! - I started the work when I came across FRAM/MRAM which does not have the EEPROM/FLASH issues. The memory was serially attached and the memory manager already follows this idea... I know that @gfwilliams has published something as well that takes the paging and equal/balanced(?) erasing/rewriting into consideration. @drazzy, we are not the only one who like to tool with memory! Posted at 2016-03-06 by Wilberforce Here is the web server example:
The webserver - using the FlashStore object to retrieve, it assumes you have a saved
The ico and image assets are saved, then the index.html root document and /js/app.js The webserver code searches the store, and if the content is matched it s served from the flash, using the .pipe method. When the button is clicked, a /json method is called, and this returning the current time back to the browser... Attachments: Posted at 2016-03-06 by Wilberforce
At this stage I've decided to keep it very simple. This is the structure used to store items:
The magic is in the The page size is 4K - currently each object takes up at least on page. This seems wasteful, however the trade off is speed. I did not think it was worth the extra trouble of storing intra page and managing indexes. Given that you can store a complex js structure, you could pack everything you wanted in a structure and store that.
The A future enhancement could be to have an array of free pages, and this could be checked and used for a new write.
In my case, I wanted to store web pages, and modules. Both of these are easy to re-populate, so rather than garbage collect and move pages around (with limited available memory), it is more straightforward to call I wanted the Posted at 2016-03-06 by Wilberforce Compressed objects. The
With the compress options, the headers are modfied and the content is compressed, and this is what is sorted in flash. When the webserver .pipe method retrieves the object, it is sent back compressed to the browser and the browser unzips on the fly. This means that we don't need gzip/ungzip libraries for espurino, but can store large libraries for the browser front end efficiently with no overhead. It's not particularly quick - just under 9 secs to load.However it means a web server can be set up in AP mode, and not be connected to the internet, and have bootstrap.css! Posted at 2016-03-06 by Wilberforce We can also cache Modules in Eprom, and load on demand:
This means you can use require on the left hand side of the IDE on a pre-cached module, and then use that module. Posted at 2016-10-20 by Aleksandrs I have litle bug i don`t understand ...
Posted at 2016-10-22 by Wilberforce You need to use the module in 2 stages. The first is to use the write module to load your module into flash. You can add it as a string, or use the wget method to load it. Then use the flash item method to pull the string from flash and add to the module cache. In your example you would not use the 2nd require, as the first would have already added it. The error you are getting is due to the module not getting added to then flash with the write method first, so the retrieved string is empty so the module.add fails Posted at 2016-12-09 by @MaBecker @wilberforce - very cool - thanks for sharing ! downoaded the zip file and stored the js files in the module folder running a ESP8266 with 1v89 tried this
and got
Inside of FlashStoreWrite there are two require statements that seems to cause the Error. loading them separately works fine
no Errors and no Warnings... @wilberforce any idea why this is not working on my side ? Posted at 2016-12-09 by Wilberforce @MaBecker I'll look into it. Posted at 2016-12-20 by @MaBecker Hi @gfwilliams, are there some changes made in WebIDE that the snippet shown in #11 fails ? I downloaded FlashStore.zip and moved files to the modules folder. console.log contains WebIDE CONSOLE information of last try. Attachments: Posted at 2016-12-20 by @gfwilliams Not that I know of. What's the error? Log all looks ok Posted at 2016-12-20 by @MaBecker good to know #11 shows the error Posted at 2017-03-12 by EthraZa FlashStore has something to do with FlashEEPROM? Posted at 2017-03-12 by @MaBecker Hi @EthtaZa, this three modules form @wilberforce are based on Flash Library. It is using free flash areas to write and read simple and complex types of data. Posted at 2018-12-03 by @gfwilliams Just to update this, there's now:
These work on all platforms. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-03-05 by Wilberforce
I'm still refining this, however recent activity on gitter has prompted me to publish this now!
https://github.com/wilberforce/EspruinoDocs/tree/master/modules
There are 3 modules used.
The FlashStoreWrite module is used to populate flash with assets that you want access to in your real application. It is a key based storage system, that takes a key, and stores a js object against it. This can then be recovered using the FlashStore module.
The basic usage is:
The FlashItem object is used for recovering the stored object, which has methods toString() and valueOf();
var str=fs.item('example').toString();
The flashItem also knows about the types of object so treats the differently.
This allows us to store things like web assets such as css and js files, images and have them served by a the http server object (using pipe so that not much memory) is consumed.
We can also store modules in flash, and load them on demand.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions