Read the statement by Michael Teeuw here.
Passing Variables Around
-
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!
-
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
-
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;} -
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' } }
-
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?