Is there any easy way build in to save Data from a Module so it can persist over restarts? I could probably save everything to a .json but I’m not sure if that is a good Idea. The documentation mentions nothing.
j.e.f.f Project Sponsor Module Developer last edited by
@Kiina It’s not documented, because most of the modules use a real-time data feed, where after the mirror restarts, the first thing the modules do is fetch new up-to-date data – no need to cache previous data through restarts.
I’m assuming you’re building a custom module where this isn’t practical. In order to persist data over restarts, you’ll want to save the data to the SD card periodically, and then have the Module look for it when MM restarts. Keep in mind that you’ll have to do this in the node_helper.js file, as the front-end portion of the Module - the part that controls the display of your Module’s information on the screen – does not have access to the file system.
If the amount of data you need to save is not that large then any text format you are comfortable working with is fine, be it JSON, CSV, plain text in a structure you invent, etc. Google for help with working with the file system in NodeJS to get started. If you have a lot of data to save, you might want to consider installing something like MySQL on your Pi and storing the data in tables.
I hope that helps!
@j.e.f.f said in Persistent data:
I’m assuming you’re building a custom module where this isn’t practical
Yeah my module gets OAuth data back which needs to be stored if the user doesn’t want to authenticate the mirror everytime it restarts/crashes. So I hoped there was some kind of datastorage build in for small stuff. I will try it with a .json file