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

    Posts

    Recent Best Controversial
    • RE: Timetable with (almost) static data

      Node can execute a php – if a php.ini is in the PATH – with this in the node_helper.js :

      const runner = require("child_process");
      runner.exec("php " + proxy + " " + params, function(err, data, stderr) {
      //         ("php timetable.php parameter", function(err, data, stderr) {
          var content = data; // "Clean your room - now!"
          this.workWithTheData(content);
      });
      

      timetable.php :

      < ? php // remove spaces
      $params = explode(",", $argv[1]); // example, you can leave parameters out (see above)
      $content = "Clean your room – now!";
      echo $content;
      ?>
      

      Now that we know we can, let’s talk about if we should: I like it, I use it for a proxy to call APIs while ignoring CORS. BUT I don’t think it makes sense in this case! It’s like using a hammer to fix a loose screw.

      To show a static website in the iframe, HTML is enough. Do you really need server side scripts?

      If you want a csv, use this in the node_helper.js :

      const fs = require("fs"); // before module.exports = ...
      
      getTimeTable: function() {
          var rawdata = fs.readFileSync('modules/my-module/file.json'); // or txt or csv
          var timetable = JSON.parse(rawdata); // in this case
          this.sendSocketNotification("Response", timetable);
      }
      

      EDIT: I know that for users with basic HTML or even PHP knowledge, the iFrame solution is an easy win. Use runner or fs if you want to import data directly into your own module.

      posted in Requests
      D
      doubleT
    • RE: Where are you from?

      Hamburg, Germany

      posted in General Discussion
      D
      doubleT
    • RE: Trim the fat in a JSON file?

      Ok, I checked the code of that module, values: ["price"] IS the correct setting for the config but getValue: function(data, value) {... has an error.

      getValue: function(data, value) {
          if (data && value) {
            var split = value.split(".");
            var current = data;
            while (split.length > 0) {
      //        current = current[split.shift()]; // WRONG!
                current = current[0][split.shift()];
            }
            return current;
          }
          return null;
      },
      

      I’d have written that totally different, but yeah, at the moment, the problem is, that the object it should be looking for is nested within a wrapping object. Add the [0]and you should be getting your results.
      Edit: Could also be a problem with the received json format.

      posted in Troubleshooting
      D
      doubleT
    • RE: call API (no CORS), used to do it with php proxy

      That’s what I thought.

      I got it done thanks to this blog entry about calling PHP within node.js via Child Process Dependency. Actually, now that I know about this, it’s quite easy, you just have to have PHP installed and in your PATH (that took me a while …).

      (relevant part of) node_helper.js

      getData: function(payload) {
           var self = this;
           var runner = require("child_process");
           var proxy = "modules/my_module/proxy.php";
           var source = "http://apisource.de/api/getPrices.php?id=12300123";
           runner.exec("php " + proxy + " " + source, function(err, data, stderr) {
                var json = JSON.parse(data);
                self.sendSocketNotification("MSG", json);
           });
      }
      

      proxy.php is nearly unchanged from my first post: (php tags not showing up)

      $params = explode(",", $argv[1]);
      $file = file_get_contents($params[0], true);
      echo $file;
      

      A node child process is started, it uses PHP (has to be in the env. PATH) to open the file it is handed (proxy) and attaches the parameter “source” to that call. The proxy.php gets the contents of “source” and echo’s it.
      The child process receives the echo’ed data, I parse it to JSON and send that back to the module.

      It’s working, but let me know if you see any flaws or anything I could improve. Thanks a lot.

      Oh, and no, there’s no way around that “file_get_contents => echo proxy” atm.

      Torben

      posted in Development
      D
      doubleT
    • RE: MMM-OlympicGames

      @dnks23 http://www.medalbot.com/api/v1/medals, it’s in the node_helper.js

      posted in Sport
      D
      doubleT
    • RE: Font Help Info

      When you close the browser, MM is still running as a server/process in the background. If you stop and start it or directly restart it, there is no need to restart the Pi. What restarting the Pi does is just a very complicated way to stop the MM process. ;)
      Do you use PM2 to start MM on boot? Use

      pm2 restart mm
      

      See here: https://github.com/MichMich/MagicMirror/wiki/Auto-Starting-MagicMirror

      Or with npm, stop the package and start it again.

      Btw.: what text box? The console?

      posted in General Discussion
      D
      doubleT
    • RE: Need help with internet monitor-module

      And please check the following link: https://forum.magicmirror.builders/topic/4247/how-to-post-code-on-the-forum-for-absolute-beginners/2

      Right now, the config.js you posted is near-unreadable.

      posted in Troubleshooting
      D
      doubleT
    • RE: Real Time ECG

      For anything involving a graph drawn from JS(ON) data, I can only recommend highcharts.

      It’s possible to display dynamic graphs from live data. Example: https://www.highcharts.com/stock/demo/dynamic-update/
      https://www.highcharts.com/docs/working-with-data/live-data

      Your python code could provide a JSON and the MM-module calls the JSON and prints the graph.

      I’ve used highcharts before but never dynamically like in the example above.
      Here’s an example where I used it in a module: https://github.com/TTigges/MMM-Oiltank/blob/master/MMM-Oiltank.js

      posted in Development
      D
      doubleT
    • RE: Changing wether API?

      @navyvette87
      If you’re talking about the default weather modules, they only work with keys for http://www.openweathermap.org
      But you can remove those from your config and add MMM-Wunderground instead following its instructions: https://github.com/RedNax67/MMM-WunderGround

      posted in General Discussion
      D
      doubleT
    • RE: Really confused

      @Duke86 said in Really confused:

      pi@raspberrypi:~/MagicMirror $ cd MagicMirror
      bash: cd: MagicMirror: No such file or directory

      You are already in the directory “MagicMirror”. cd (change directory to) can’t find the directory because you are already inside.

      pi@raspberrypi:~/MagicMirror $ nmp install
      bash: nmp: command not found

      Just a typo, it’s “npm”, not “nmp”.

      posted in Troubleshooting
      D
      doubleT
    • 1 / 1