Hello, I would like to store a simple integer value (1-200) on the Puck.js without stopping the Bluetooth connection. If I would use save(), the connection is lost. And it is definitely too much for storing only one variable. Is there a better way to do it without interrupting the rest of the Puck.js?
Espruino has an option to write into the unused / free flash eeprom area (located in the address space after the firmware).
Take a look here:
You can convert your data to a json string to store or use these classes:
Thanks, could you tell me how to securely use Flash module? I would not like to override Espruino or something else. Do you have a short example how to write and read an integer value from Flash storage?
In the console, enter Flash.getFree(); and you will get back a list of objects for each free page in Espruino Flash. Each object has an address where the free page starts, and a size information about how many bytes the page contains. With that information you know where you can write without running into problems such as overwriting Espruino code and bricking your device.
Note though, that this may change with an any update or change of the firmware. Therefore, before you update, read the data back, store it somewhere, do an update of Espruino, then get the free pages again, adjust your writing/reading positions of the Flash EEPROM if needed, and load the data back into Espruino.
I'd suggest you use the FlashEEPROM module: http://www.espruino.com/FlashEEPROM
It provides a nice, safe interface to the flash memory which allows you to read and write data pretty easily. It also does it in a way that will be careful not to wear out flash memory if you do lots of writes.
There are some good examples of usage on that page - for instance:
var f = new (require("FlashEEPROM"))();
//.. you can write to any address between 0 and 255, with any data up to 65536 chars long
// returns new Uint8Array([72, 101, 108, 108, 111])
// returns "World"
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem