• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Persistent data

Scheduled Pinned Locked Moved Development
3 Posts 2 Posters 1.6k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    Kiina
    last edited by Aug 16, 2017, 5:27 PM

    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 1 Reply Last reply Aug 17, 2017, 2:36 PM Reply Quote 0
    • J Offline
      j.e.f.f Project Sponsor Module Developer @Kiina
      last edited by Aug 17, 2017, 2:36 PM

      @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!

      1 Reply Last reply Reply Quote 1
      • K Offline
        Kiina
        last edited by Aug 17, 2017, 2:46 PM

        @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

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy