How-to run code from flash #6072
Replies: 1 comment
-
Posted at 2019-02-10 by Wilberforce @tve - welcome back! Posted at 2019-02-10 by @MaBecker I like to save code to Storage and than require it, this save a big amount of vars. Tested with tinyMQTT and a strip down of SSD1306 for I2C only (SSD1306_I2C). snippet how to store it
snippet to use it
Posted at 2019-02-11 by @gfwilliams Good to hear from you again! Thanks for posting that code up - I'm sure that'll be useful to others.
It is actually linked quite a bit (FAQ,Troubleshooting,Quick start, etc). But where did you look where it wasn't mentioned and I'll get a link added. Posted at 2019-02-11 by tve
@MaBecker, can you explain the advantages of your scheme over what I'm using? It's quite a bit of additional work.
Hmmm, my bad. I could swear that typing 'saving' into the search box brought up nothing, but now it does, so I must have been too tired to see it or something... I mainly looked around in the tips&tricks, tutorials, modules, and esp8266 pages. Posted at 2019-02-11 by @MaBecker Let me use this snippet and make the difference visible with process.memory().
how many vars you save depends on the size of the module . That should justify the extra effort ;-) ESP8266_4MB board has now 48 pages to store any stuff you like, check the build content Hint: At the moment storage is only working for the first segment, read issue #1507 Why not write a script as workaround until someone adds this feature into the WebIDE or command line tool
Posted at 2019-02-12 by opichals @tve The approach you are using is basically what I do as well.
Using Rollup https://github.com/espruino/EspruinoTools/blob/f8a5ed8bd565070d33154d9196ad9e51f8aa3c33/plugins/minify.js#L52-L65 you'll be able to create bundles that only contain the module exports that were actually used in the application. My CLI preferred approach is to use the https://github.com/opichals/rollup-plugin-espruino-modules to do all the JS magic and use the espruino cli to only 'upload' the resulting bundle to the board just as @tve mentioned. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-02-10 by tve
After being away for a year it's nice to see all the progress on Espruino!
I did struggle for quite some time to update my stuff and to get my code working again under V2.01, so I thought I'd write up a quick how-to so I remember the next time I try to do something :-) Maybe it also helps someone else 'cause very little of this is spelled out anywhere that I could find (the best info is at http://www.espruino.com/Saving but that page is not linked to from any other page on www.espruino.com!)
Requirements:
I couldn't do an OTA update from pre-V2 of Espruino to V2.x due to a changed flash layout (512 vs 1024KB partitions). I have esp-12e modules with 4MB flash, so I installed the official espressif tool https://github.com/espressif/esptool/ and flashed using:
In the IDE I had to set the options SAVE_TO_FLASH to 1 and MODULE_AS_FUNCTION to true. But I don't want to use the IDE...
So I installed the espruino cli:
/home/sw/node-v8
(non-std location, use any dir you like)/home/sw/node-v8/bin/npm install espruino
In order to ensure that I can run the cli using node-v8, I created a little shell script I call
espruino-v8
:To flash an application I have the main file in a
projects
subdirectory and the modules in amodules
subdirectory. I simplyrequire(...)
the module in the main file. The flashing command is:The -w option means that espruino stays connected and shows me the console output.
The application uses an
onInit()
to start and that gets invoked automatically at the end of the upload.Beta Was this translation helpful? Give feedback.
All reactions