MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. telmini
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 7
    • Groups 0

    telmini

    @telmini

    0
    Reputation
    5
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    telmini Unfollow Follow

    Latest posts made by telmini

    • RE: Config modules from external file (JSON)

      It could probably be that the XmlHttpRequest is async and the page is already loaded when the request has finished executing.

      posted in Troubleshooting
      telminiT
      telmini
    • RE: Config modules from external file (JSON)

      Sorry, this is the output.

      > magicmirror@2.11.0 start /home/pi/MagicMirror
      > DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js
      
      [2021-01-27 16:55:09.858] [LOG]    Starting MagicMirror: v2.11.0
      [2021-01-27 16:55:09.878] [LOG]    Loading config ...
      [2021-01-27 16:55:09.892] [LOG]    Loading module helpers ...
      [2021-01-27 16:55:09.896] [LOG]    Error: ENOENT: no such file or directory, access '/home/pi/MagicMirror/js/../modules/default/currentweather/node_helper.js'
          at Object.accessSync (fs.js:202:3)
          at Object.fs.accessSync (electron/js2c/asar.js:491:38)
          at Object.fs.accessSync (electron/js2c/asar.js:491:38)
          at loadModule (/home/pi/MagicMirror/js/app.js:124:7)
          at loadNextModule (/home/pi/MagicMirror/js/app.js:166:5)
          at loadModules (/home/pi/MagicMirror/js/app.js:177:3)
          at /home/pi/MagicMirror/js/app.js:223:4
          at loadConfig (/home/pi/MagicMirror/js/app.js:72:4)
          at App.start (/home/pi/MagicMirror/js/app.js:211:3)
          at Object.<anonymous> (/home/pi/MagicMirror/js/electron.js:115:7) {
        errno: -2,
        syscall: 'access',
        code: 'ENOENT',
        path: '/home/pi/MagicMirror/js/../modules/default/currentweather/node_helper.js'
      }
      [2021-01-27 16:55:09.924] [LOG]    No helper found for module: currentweather.
      [2021-01-27 16:55:09.926] [LOG]    All module helpers loaded.
      [2021-01-27 16:55:10.246] [LOG]    Starting server on port 8080 ... 
      [2021-01-27 16:55:10.256] [INFO]   You're using a full whitelist configuration to allow for all IPs
      [2021-01-27 16:55:10.268] [LOG]    Server started ...
      [2021-01-27 16:55:10.268] [LOG]    Sockets connected & modules started ...
      [2021-01-27 16:55:10.428] [LOG]    Launching application.
      ^[$
      
      

      I don’t understand why it’s trying to go to this path

      Error: ENOENT: no such file or directory, access’/home/pi/MagicMirror/js/…/modules/default/currentweather/node_helper.js’

      posted in Troubleshooting
      telminiT
      telmini
    • RE: Config modules from external file (JSON)

      @telmini said in Config modules from external file (JSON):

      loadJSON(“./modules.json”)

      But that bug/crash is inside Magic Mirror code. Or is related to the path defined here “loadJSON(”./modules.json")"?

      posted in Troubleshooting
      telminiT
      telmini
    • RE: Config modules from external file (JSON)

      So, it can detect that the json file has the “currentweather” module, but then fails to load it properly.

      Any help?

      posted in Troubleshooting
      telminiT
      telmini
    • RE: Config modules from external file (JSON)

      So, I tried this, as seen on another example in this thread

      config.js:

      var config =
      {
        address: "0.0.0.0",
        electronOptions: {},
        ipWhitelist: [],
        language: "pt",
        logLevel: ["LOG", "WARN", "ERROR", "DEBUG"],
        modules: loadJSON("./modules.json"),
        paths: {
          modules: "modules",
          vendor: "vendor"
        },
        useHttps: false,
        httpsPrivateKey: "",
        httpsCertificate: ""
      };
      
      
      function loadJSON(filePath){
        if (typeof module !== "undefined") {
              return require(filePath);
          } else {
          var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
          var xhr = new XMLHttpRequest();
      		xhr.overrideMimeType("application/json");
      		xhr.open("GET", filePath, true);
      		xhr.onreadystatechange = function () {
      			if (xhr.readyState === 4 && xhr.status === 200) {
      				// needs error handler try/catch at least
      				let fileinfo = null;
      				try {
      					fileinfo = JSON.parse(xhr.responseText);
      				} catch (exception) {
      					// nothing here, but don't die
      					Log.error(" loading json file =" + file + " failed");
      				}
      				return fileinfo;
      			}
      		};
      		xhr.send(null);
        }
      }
      

      modules.json

      [{
            "module": "currentweather",
            "position": "top_left",
            "config": {
              "location": "Lisboa",
              "locationID": "2267057",
              "appid": "314d9c29c18fd11e79034c56e1348f4c",
              "iconTable": {
                "01d": "wi-day-sunny",
                "02d": "wi-day-cloudy",
                "03d": "wi-cloudy",
                "04d": "wi-cloudy-windy",
                "09d": "wi-showers",
                "10d": "wi-rain",
                "11d": "wi-thunderstorm",
                "13d": "wi-snow",
                "50d": "wi-fog",
                "01n": "wi-night-clear",
                "02n": "wi-night-cloudy",
                "03n": "wi-night-cloudy",
                "04n": "wi-night-cloudy",
                "09n": "wi-night-showers",
                "10n": "wi-night-rain",
                "11n": "wi-night-thunderstorm",
                "13n": "wi-night-snow",
                "50n": "wi-night-alt-cloudy-windy"
              }
            }
        }]
      

      And this is the output:
      ![0_1611766820659_output.png](Uploading 100%)

      output

      posted in Troubleshooting
      telminiT
      telmini
    • RE: How to load config data from file?

      Did you manage to make this work? I’m trying to do kinda the same.

      Thanks

      posted in Troubleshooting
      telminiT
      telmini
    • Config modules from external file (JSON)

      Hi.

      I want to define my modules [] in a separate JSON file and then have config.js read from that file and populate it.

      Is it possible? something like this

      var config = 
      {
        address: "0.0.0.0",
        electronOptions: {},
        ipWhitelist: [],
        language: "pt",
        modules: loadJSON("configuration.json"),
        paths: {
          modules: "modules",
          vendor: "vendor"
        },
        useHttps: false,
        httpsPrivateKey: "",
        httpsCertificate: ""
      };
      
      function loadJSON(filePath){
         try {
              var fs = require('fs');
              var path = require('path');
              var filename = path.resolve(__dirname, filePath);
              var jsonFile = JSON.parse(fs.readFileSync(filename));
              return jsonFile;
            } catch (e) {
               console.error(e);
                return [];
            }  
      }
      
      

      Thank you

      posted in Troubleshooting config modules json file
      telminiT
      telmini