• 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.

Passing Variables Around

Scheduled Pinned Locked Moved Solved Development
7 Posts 3 Posters 4.1k Views 3 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.
  • C Offline
    Cato Module Developer
    last edited by Dec 1, 2016, 9:16 PM

    I really don’t understand what you are trying to do! It seems you are trying to put some code inside config.js?!?

    1 Reply Last reply Reply Quote 0
    • J Offline
      jeremytripp
      last edited by Dec 1, 2016, 9:55 PM

      Yes, @Cato I was afraid I overcomplicated the question. I actually tried to simplify it later, but apparently there’s a time limit on editing. Let me try simplify.

      Let’s say I want to take the Hello World module and base it’s text on a variable. That’s the simplest form.

      So hypothetically, my config.js could look like:

      var someVariable = "myString";
      var config = { 
          modules: [
         {
              module: 'helloworld',
                   position: 'top_bar',
                   config: {
                       text: someVariable
                   }
              }
          ]
      }
      

      Unfortunately, using a variable in place of an actual string of text seems to break the config file. Surely there must be a way!

      1 Reply Last reply Reply Quote 0
      • C Offline
        Cato Module Developer
        last edited by Dec 1, 2016, 10:07 PM

        Ok, I understand what you are trying to do. But I’m pretty sure it’s not possible to insert variables into the config file.

        If you can’t access your MongoDB using a client side API, I would suggest adding a node_helper to your module and sending “notifications” between frontend (module) and backend (node_helper) asking for the information you need? You can do this in the start-part of the module if it is an one time thing.

        If you haven’t, make sure to read and understand this documentation: https://github.com/MichMich/MagicMirror/tree/develop/modules

        1 Reply Last reply Reply Quote 0
        • P Offline
          plumcraft
          last edited by plumcraft Dec 2, 2016, 8:11 AM Dec 2, 2016, 8:09 AM

          Hello,

          I was trying to clean my config file and the following is working for me.
          Let me know if it’s working for you.


          /* Magic Mirror Config Sample
          *

          • By Michael Teeuw http://michaelteeuw.nl
          • MIT Licensed.
            */

          var stocks_list = “INDEXSTOXX:SX5E”;
          var weather_api_key = “XXXXXXXX”;
          var weather_pws = “XXXXXXXX”;
          var hue_bridge_ip = “XXXXXXXX”;
          var hue_user_id = “XXXXXXXX”;
          var voice_code = “JARVIS”;

          var alert = { module: ‘alert’ };

          var stocks = { module: ‘mmm-stocks’, position: ‘top_bar’, config: { stocks: stocks_list, updateInterval: 37000 } };

          var clock = { module: ‘clock’, position: ‘top_left’ };
          var weather = { module: ‘MMM-WunderGround’, position: ‘top_left’, config: { apikey: weather_api_key , weather_pws ,hourly: ‘1’, alerttruncatestring: “french:” } };

          var hue = { module: ‘MMM-Hue’, position: ‘top_right’, config: { bridgeip: hue_bridge_ip , userid: hue_user_id ,colour: false} };

          var hide = { module: ‘mm-hide-all’, position: ‘bottom_right’ };

          var voice = { module: ‘MMM-voice’, position: ‘bottom_bar’, config: { keyword: voice_code, microphone: 1, debug: true } };

          var config = {
          port: 8080,
          language: ‘en’,
          timeFormat: 24,
          units: ‘metric’,
          modules: [ clock, hue, stocks, voice, weather ]
          };

          /*************** DO NOT EDIT THE LINE BELOW ***************/
          if (typeof module !== ‘undefined’) {module.exports = config;}

          1 Reply Last reply Reply Quote 0
          • C Offline
            Cato Module Developer
            last edited by Dec 2, 2016, 9:33 AM

            @jeremytripp

            Is this what you really want:

            var myName = "Cato";
            var myModule = { module: 'MyModule', position: 'top_left', config: { name: myName }};
            console.log(myModule);
            

            Output:

            { module: 'MyModule',
              position: 'top_left',
              config: { name: 'Cato' } }
            
            
            1 Reply Last reply Reply Quote 0
            • J Offline
              jeremytripp
              last edited by Dec 2, 2016, 4:17 PM

              Basically yes, that’s what I’m trying to do. Would that work, assuming I set it up as a new module according to the guidelines you sent earlier? (thank you by the way, that helped a lot).

              Essentially I’m just trying to be able to pull data from my MongoDB (I will probably roll this into its own module – right now I’ve committed the sin of modifying app.js directly until I get my bearings). Then use the Mongo data to populate data in other modules (think Hello World, Compliments, etc.).

              It sounds like I will need to create a second module that essentially takes my Mongo data and sends it in the form of a JSON object variable to other modules using sendNotification() and then have them update the DOM to reflect the change. I know there are some nuances, but for the sake of brevity, am I generalizing/thinking about it correctly?

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                6/7
                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