Storing persistent data

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
hoh
Posts: 2
Joined: Thu Mar 10, 2016 9:52 pm

Storing persistent data

Post by hoh » Thu Mar 10, 2016 10:13 pm

Hi all,

I would like to save data that survives reboot, but did not find any documentation on how to do it on ESP8266. I found the function flash_write, but am not sure how to use it and the filesystem API is not present yet.

Is there a way to store a string/array-of-bytes from Python and load it from Python after reboot ? How would it work ?

Thanks !

woodat
Posts: 20
Joined: Wed Feb 17, 2016 9:24 pm

Re: Storing persistent data

Post by woodat » Thu Mar 10, 2016 11:14 pm

I played around with their basic file storage and it holds files after complete power loss. Was a simple matter of the following commands to write a file:

import boot_
f=open("myfile.txt","w") # opens a file for writing.
f.write("some data! Hooray data!")
f.close()


And to read (assuming you've rebooted)

import boot_
import os
os.listdir() # just for fun, get a list of existing files
f=open("myfile.txt","r")
print(f.read())
f.close()



That's all I've got for now. Only had a few minutes to play thus far. I was debating writing a script to open files on a local webserver and write them into memory as a way to transfer bigger scripts in, but I think I heard they're working on some upip style methods. (I have to think of these things given I only have ESP12s laying about. None of those wonderful looking huzzahs or feathers or whatnot with their USB drive detection)

hoh
Posts: 2
Joined: Thu Mar 10, 2016 9:52 pm

Re: Storing persistent data

Post by hoh » Wed Mar 16, 2016 1:54 pm

Thanks, that worked.

The new firmware version announced today ships with the filesystem enabled by default, making it easier to achieve this.

woodat
Posts: 20
Joined: Wed Feb 17, 2016 9:24 pm

Re: Storing persistent data

Post by woodat » Wed Mar 16, 2016 2:13 pm

I saw that. I'm flashing my dev chip now so I can take it to work and play

Post Reply