Is the Tufty file system really read-only?

I’m writing an app where I want to cache some online data locally on the Tufty (just a small JSON file). It seems I can’t do that (getting the JSON error 30 - indicating read only file system). Is there any setting that would allow me to do that - or some “special” folder? I haven’t seen anything in the badgeware.io/docs that mentions file saving - so curious if I missed that. Thanks!

Oh… curious… digging into the example apps (clock for instance) I see there is a badgeware.state construct which appears to survive between app runs (just guessing). Can’t find any documentation on the limitations of that. I don’t need a lot of space.. but.. would be nice to know how much I can push that.

/state should be writable. Probably / is also writable, /system is not writable.

There is a class State that lets you save state of your app. But this seems to be only operating on json, but that is exactly your usecase. See tufty2350/modules/common/badgeware/state.py at main · pimoroni/tufty2350 · GitHub

1 Like

Umm.. yep.. my edit mentions I discovered State. Working great for my needs right now. Phew! Thanks for the link to the github class. I was looking for more of a “this is how to use it / these are the limitations” - which don’t seem to exist. Either way - thanks for the response. Appreciated!

There’s a docs page on State waiting to go up, but the basics are pretty easy to see from the module in GitHub -

State.save(name, data) - saves data to a json file called name in /state, where data is a dictionary containing simple types

State.load(name, dict) - loads from the name json file into the specified dictionary. If there’s no such file, it creates one using the current contents of dict.

State.delete(name) - deletes the specified state file.

It’s worth also mentioning that you should be able to use all of the usual MicroPython read / write functions in /state, for other kinds of data.

1 Like

Thanks for that. I have things running well so far (storing ISS pass data for now). I was happy to stumble across this. Now… wondering if I could save an image file in there encoded in base64? Might have to give that a try, Wanted to see if I can pull in some images from an online source.

No need to encode anything. Just open a file below /state (e.g. /state/myimage.jpg) in binary mode and write the data to the file.