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

    Posts

    Recent Best Controversial
    • RE: How to best process an [object Promise]?

      I also tried another variant, but that failed too:

          radarPing: function() {
              console.log("ENTER (inside)");
              try {
                  var ping = radar(-8.20917,114.62177,-9.28715,115.71243); 
                  ping.then({
                  return ping;
                  //...
                  });
                  console.log("GOT DATA: ", ping);
                  //return await ping;
              } catch(error) {
                  console.log("API ERROR: ", error);
              }
              //return "None";
              console.log("EXIT (inside)");
          },
      
          readData: function() {
              var radarData = "";
              radarData = this.radarPing;
              console.log("The DATA:\n" + radarData);
      ...
      
      posted in Development
      E
      E3V3A
    • RE: How to best process an [object Promise]?

      @Mykle1 said in How to best process an [object Promise]?:

      @ninjabreadman said in How to best process an [object Promise]?:

      automagically

      Absolutely the best term I have heard to date. :-)

      :) Especially in this context! I’m only now starting to understand why it’s called a magic mirror… Whatever you guys manage to create, it seem to have been done by development magic…

      But, anyway, my problem is surely just a lack of conceptual and technical knowledge.

      In my node_helper.js I was tryign to do this:

      const NodeHelper = require("node_helper");
      const fs = require('fs');
      const async = require('async');
      const radar = require('radar-api'); // This API return improper JSON
      
      module.exports = NodeHelper.create({
      ...
          async function radarPing() {
              console.log("ENTER (inside)");
              try {
                  const ping = await radar(-8.20917,114.62177,-9.28715,115.71243);
                  console.log("GOT DATA: ", await ping);
                  return await ping;
              } catch(error) {
                  console.log("API ERROR: ", error);
              }
              //return "None";
              console.log("EXIT (inside)");
          },
      
          readData: function() {
              var radarData = "";
              radarData = radarPing();
              console.log("The DATA:\n" + radarData);
      ...
      

      but that ended up with some weird errors, like:

                  const ping = await radar(-8.20917,114.62177,-9.28715,115.71243); 
                                     ^^^^^
      SyntaxError: Unexpected identifier
          at Object.exports.runInThisContext (vm.js:76:16)
          at Module._compile (module.js:528:28)
      

      Since, I’ve only started to learn about Promises, sync/await, just 2 days ago, I must be missing a lot. Because all the examples I’ve seen, are using more or less this way of writing.

      So how the eeek do I make sure that what is returned by the api/poll function, is actual data and not an [object Promise], and how can I handle the Promise { } that is returned in advance?

      I’m overwhelmed…

      posted in Development
      E
      E3V3A
    • RE: How to best process an [object Promise]?

      @tbbear Hi! Thank you, but that is quite an extensive code. Can you pinpoint where you do this?

      posted in Development
      E
      E3V3A
    • RE: current Weather form .json file

      Maybe this one ?

      posted in Utilities
      E
      E3V3A
    • RE: Newbe help please

      @morso IDK how old is your MM that was working, but now you need to go to: ~/MagicMirror/installers/ and run the mm.sh script with pm2. I use an alias for this:

      alias mm2='cd $HOME/MagicMirror/installers/; pm2 flush; pm2 start mm.sh && cd $OLDPWD'
      

      with:

      $ cat ~/MagicMirror/installers/mm.sh
      cd ~/MagicMirror
      DISPLAY=:0 npm start
      
      posted in Troubleshooting
      E
      E3V3A
    • How to best process an [object Promise]?

      I have an API that is returning a JSON object as an [object Promise]. At first I was completely cluless to what this was. I now understand it’s because the API is using some asynchronous function to obtain and present the data. I have spent the last day or two to reading up about this. In particular about Promises, async/await, fetch/catch, and even Generators.

      But since I’m completely new to this kind of JS programming, I’m rather overwhelmed by the various kinds of methods used for doing this. I could need a small hint of guidance for what to look into. Basically a super simple crash-course to get people like me started in the framework of MM modules. In addition, I’ve read that even seasoned developers get this wrong regularly.

      What I think I need to add in my node_helper is:

      • read the config file to get an option to be used in the API call
      • make the promised API call
      • wait for correct JSON response from API call
      • push JSON to MMM-module

      All the above need to be repeated on a regular interval. (I’m not sure this “polling” need to be implemented separately here, or if the MM config.js reload mechanism is enough.

      What is the simplest method to implement that?
      I’d love to hear from what you guys think.

      PS. I’ve read that async/await is syntactically simpler to use.

      posted in Development
      E
      E3V3A
    • RE: Is node_helper really required?

      @strawberry-3.141 Oh!? That is funny, because I removed it, and there is no change in anything, module ran fine without it. Perhaps because I’m not using most of the content from that file, while the rest is already defined?

      posted in Troubleshooting
      E
      E3V3A
    • RE: ECONNREFUSED when trying to get JSON from my server (MMM-json-feed)

      From here:

      ECONNREFUSED (Connection refused): No connection could be made because the target machine 
      actively refused it. This usually results from trying to connect to a service that is inactive on the 
      foreign host.
      
      posted in Troubleshooting
      E
      E3V3A
    • RE: Is node_helper really required?

      It is not, and should not, AFAICT.

      posted in Troubleshooting
      E
      E3V3A
    • Is node_helper really required?

      I see a lot of people putting: const NodeHelper = require("node_helper"); in their node_helper.js file. Is this right or even necessary?

      It doesn’t make much sense to state that a file require itself! And if it is referring to MM’s internal node_helper, then shouldn’t the MM core be made to recognize this by itself?

      I’m asking, because doing that, make your npm-check always complain about node_helper not being installed or missing.

      posted in Troubleshooting
      E
      E3V3A
    • RE: ECONNREFUSED when trying to get JSON from my server (MMM-json-feed)

      @toh1000 Please post JSON response. I just spent a day trying to figure out why MM is so fickly regarding non-perfect JSON being sent over the socket. Loading JSON from a variable, just fine. Pushing the exact same JSON over a socket…had problems.

      BTW. Is it correct that it says your JSON is GZIP encoded, no??

      posted in Troubleshooting
      E
      E3V3A
    • RE: Face recognition step by step

      @vintage89 Please post the link to that guide… Thx

      posted in Troubleshooting
      E
      E3V3A
    • How about a module to simply output ANSI term output?

      It would be useful and nice to have a light module that can display colored ANSI xterm shell output.
      This would be particularly useful when running shell programs that is using terminal as its primary output.

      I therefore propose to develop (unless already done?) a module called something like: MMM-Xterm for this purpose.

      What are your thoughts?

      posted in Requests
      E
      E3V3A
    • MMM-Tabulator - A demo module for using Tabulator to convert JSON data into a dynamic table

      [card:E3V3A/MMM-Tabulator]

      Hi Guys!
      I have finally completed my first module to demonstrate the use of Tabulator. Tabulator is an extremely flexible library to convert CSV, XML and JSON data into dynamic HTML tables.

      • No more DOM writing
      • No more HTML clutter
      • Easy data modification, sorting and theming

      In my MMM-Tabulator repo, there are two different versions, showing the same data.

      1. In the native MagicMirror environment (and over server) and
      2. Directly by loading embedded JSON via HTML from demo.html.

      Cheers,
      E:V:A

      posted in Education
      E
      E3V3A
    • RE: I got sucked up into a magic mirror! (and need some help)

      @raywo It’s now working and I’ve pushed all updates to repo. :)
      My first module…that does nothing. :D

      posted in Development
      E
      E3V3A
    • RE: I got sucked up into a magic mirror! (and need some help)

      @raywo Hi Ray! Fantastic!! I just had a look at running your PR, and it works great! I also commented on the PR and the working Module will be pushed and ready in the next day or two. I was so close to giving up on this, so I am extremely grateful and in beer/food/wine debt to you. Thank you!

      posted in Development
      E
      E3V3A
    • RE: What is the difference between these function definitions?

      @ninjabreadman Fantastic! Again, the best explanation I’ve heard! I love that juice analogy!

      Thank you so much for having patience with all my dumb questions. Surely a lot of them are trivial to most developers. (If you’re a moderator, feel free to mark this as solved.)

      posted in Development
      E
      E3V3A
    • RE: What is the difference between require() and getScripts()?

      @ninjabreadman Aah! Finally. Thank you. That is the most sensible explanation I’ve seen.
      (If you’re a moderator, please mark this as closed/solved.)

      posted in Development
      E
      E3V3A
    • RE: Adding jQuery

      @yawns I must be blind!?

      0_1519078979009_firefox_2018-02-20_00-22-00.png

      posted in Requests
      E
      E3V3A
    • What is the difference between these function definitions?

      I keep on seeing people adding their own functions in their MMM-Module.js.
      Some people write:

        updateDomIfNeeded: function() {
        ...
        }
      

      while others prefer to just write:

      myfunction() {
      ...
      }
      

      What is the difference to MM, if any?

      posted in Development
      E
      E3V3A
    • 1 / 1