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
    • 1 / 1