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

    Posts

    Recent Best Controversial
    • RE: Blank screen after successful install

      Are you not running npm start? Are you just opening up the index.html file? If so, please put all of the modules back and try running npm start in the ~/MagicMirror directory.

      Please take a look at the Complete Setup Tutorial to see how to run the program.

      posted in Troubleshooting
      mochmanM
      mochman
    • RE: Trying to write my own Module...

      Glad it all worked out for you!

      posted in Development
      mochmanM
      mochman
    • RE: Trying to write my own Module...

      Looks like you need to modify your other if/then statement. The one you’ve modified checks both the name and watts to see if they are !=0. Since the name always !=0, it’s displayed.

      posted in Development
      mochmanM
      mochman
    • RE: Module ignoring node_helper.js?

      node_helper.js doesn’t output console.log() to the same place the MMM-HiWorld.js does. You’ll see the log pop up in the npm output. You can see the data when you run npm start on the raspberry pi. If you are using pm2 to autostart Magic Mirror, you can ssh into your pi and run
      tail -f ~/.pm2/logs/mm-out-0.log to see the console messages. You can also run tail -f ~/.pm2/logs/mm-error-0.log to see all of your node_helper.js errors.

      posted in Development
      mochmanM
      mochman
    • RE: Trying to write my own Module...

      MMM-EMonitor.js

      Module.register ("MMM-EMonitor", {
      
          //default module config.
          defaults: {
              // Insert defaults here
              interval: 900000, // Every 15 mins
              security_key: null,
              animationSpeed: 1000
          },
      
          getStyles: function() {
              return ["MMM-EMonitor.css"];
          },
      
          // Define the start sequence
          start: function() {
              Log.log("Starting module: " + this.name);
              this.loaded = false;
              this.xml = null;
              this.url = 'https://api.emonitor.us/location/getCurrentData?security_key=';
              setInterval(this.getCurrentData(), this.config_interval);
          },
      
         getCurrentData: function() {
              var self = this;
              var xhttp = new XMLHttpRequest();
              xhttp.onreadystatechange = function() {
                      if (this.readyState == 4 && this.status == 200) {
                              self.xml = self.parseXML(this.responseText);
                              self.loaded = true;
                              self.updateDom(self.config.animationSpeed);
                      }
              };
              xhttp.open("GET", this.url+this.config.security_key, true);
              xhttp.send();
          },
      
      
         getDom: function(){
              var wrapper = document.createElement("div");
              if(!this.loaded) {
                      wrapper.innerHTML = "Loading...";
                      return wrapper;
              }
              if(this.xml !== null){
               var table = document.createElement("table");
               table.classList.add("xsmall", "table");
               var channels = this.xml.getElementsByTagName("channel");
               for(var i = 0; i < channels.length; i++){
                 var row = document.createElement("tr");
                 for(var n = 0; n < channels[i].children.length; n++){
                      if(channels[i].children[n].tagName === "name" || channels[i].children[n].tagName === "watts"){
                      var element = document.createElement("td");
                      element.classList.add(channels[i].children[n].tagName);
                      element.innerHTML = channels[i].children[n].textContent;
                      row.appendChild(element);
                      }
                 table.appendChild(row);
                 }
               }
               wrapper.appendChild(table);
              } else {
                      console.log("Returned no Data");
                      wrapper.innerHTML = "NO DATA";
              }
              return wrapper;
         },
      
         parseXML: function(xmlStr){
              return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");
         }
      
      });
      

      Your config.js should have:

      {
                              module: 'MMM-EMonitor',
                              position: 'top_left',
                              config: {
                                      security_key: 'XXXXXXXXXXXXXXX'  //your security key
                              }
                      }
      

      This just displays everything in a large table. You may want to modify the for loop to not display data when the wattage is 0, that should get rid of a bunch of rows.

      posted in Development
      mochmanM
      mochman
    • RE: Trying to write my own Module...

      You don’t have this.xml defined anywhere in your script. If you look at @strawberry-3-141’s post, it says:

      I’m assuming that you saved your server response into this.xml

      You need to create a function that uses the URL and saves that data in a variable called xml. Since your program never does that, this.xml isn’t defined so your if/else always goes to “NO DATA”.

      Why do you have

      getCurrentData: function(that) {
             that.sendSocketNotification('GET-CURRENT-DATA', that.url);
             setTimeout(that.getCurrentData, that.config.interval, that);
          },
      

      in your program? Did you just see it in another persons code? This code snippet sends your URL to node_helper.js. Are you using that node_helper to pull the XML data from the website? If so, you’re going to need a socketNotificationReceived function to get the data and put it into the xml variable.

      The modules documentation shows you some examples of that.

      posted in Development
      mochmanM
      mochman
    • RE: Trying to write my own Module...

      Your code seems to abruptly end in the middle of the getDom() function, but from what I see, it looks like you are sending the URL to a node_helper.js that I assume will get the data you want.

      My recommendation would be to look at this page and see how to parse the XML to take out what you want. You then can use this data to create a simple table to display each <name> and <watts> in the getDom() function. I don’t think you’ll need a node_helper.js to do this though. You can probably just do it in the main .js file. Unless you’re running into a Access-Control-Allow-Origin error. Then you can get around it by using node_helper.js

      Another way people have done this has been described here.

      posted in Development
      mochmanM
      mochman
    • RE: Time wont change even if timezone is correct - WIFI

      Did you try this yet? If so, what other things have you tried?

      posted in Troubleshooting
      mochmanM
      mochman
    • RE: Trying to write my own Module...

      Can you paste your MMM-Emonitor.js using markdown? It looks like you’re missing a bunch of code.

      So the API sends you XML data and you want to pull out the wattage? Just the first one or all of them?

      posted in Development
      mochmanM
      mochman
    • RE: Magic Mirror With Amazon Alexa

      AlexaPi works pretty well too (once you get the sound to work). It has a wake word in case you don’t have a button to press. There is a Magic Mirror Module for it as well that displays what Alexa is doing on the pi (listening, speaking, errors, thinking, etc…).

      posted in Requests
      mochmanM
      mochman
    • 1 / 1