<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Need help with modules not displaying]]></title><description><![CDATA[<p dir="auto">Hi, I’m new at programming and made these two modules for a school project, but neither of them</p>
<p dir="auto">The first one is a days-left module that calculates how many days are to or from a given date:</p>
<pre><code>Module.register("days-left", {
  // config
  defaults: {
    textColor: "white",
    dates: [
      // format 'dd/MM/yyyy'
      { name: "2025", date: "01/01/2025" },
      { name: "2026", date: "01/01/2026" },
    ],
  },
  
  start: function () {
    var self = this;
    setInterval(function () {
      self.updateDom(); // updates instantly.
    }, 1000); //perform every 1000 milliseconds.
  },

  getDaysLeft: function (i) {
    const date = Date.now();
    
    const formattedDate = dateFormat(this.config.dates[i].date);
    const targetDate = new Date(formattedDate);
    
    const difference = targetDate - date;
    
    return Math.floor(difference / (1000 * 60 * 60 * 24));
  },


  dateFormat: function (date) {
    const dd = date.split("/")[0];
    const mm = date.split("/")[1];
    const yyyy = date.split("/")[2];

    const formattedDate = mm + "/" + dd + "/" + yyyy;
    return formattedDate;
  },


  getDom: function () {
    var wrapper = document.createElement("div");
    wrapper.style.color = this.config.textColor;

    for (let i in this.config.dates) {
      var days = getDaysLeft(i);
      var text = document.createTextNode(
        this.config.dates[i].name + ": " + days + " päeva pärast"
      );

      wrapper.appendChild(text);

      wrapper.appendChild(document.createElement("br"));
    }
    return wrapper;
  },
});

</code></pre>
<p dir="auto">I have my suspection on the indexing of ‘this.config.dates[i]<strong>.name</strong>’ but I’m not sure.</p>
<p dir="auto">And the other module is one that reads temp and humidity from the DHT11 sensor:</p>
<pre><code>Module.register("temperatuur", {

    // config
    defaults: {
        textColor: "white",
      },
    
    start: function () {

    },

    notificationReceived: function(notification) {
      switch(notification) {
        case "DOM_OBJECTS_CREATED":

          setInterval(()=&gt;{
            this.updateDom(500);
          }, 1000);
          break;
      }
    },
    
    getDom: function () {
      var wrapper = document.createElement("div");
      wrapper.style.color = this.config.textColor;

      this.sendSocketNotification("READ_FROM_SENSOR");
      var element = document.createElement("p");
      element.id = "text";

      wrapper.appendChild(element);
      
      return wrapper;
    },

    socketNotificationReceived: function(notification, payload) {
      switch(notification) {
        case "READ":
          var p = document.getElementById("text");
          p.innerHTML = payload;
          break
      }
    },
});
  
</code></pre>
<p dir="auto">With this one I also used a node_helper.js file:</p>
<pre><code>var NodeHelper = require("node_helper")

module.exports = NodeHelper.create({

  start: function() {
    this.temperature = '';
    this.humidity = '';
  },

  readFromSensor: function () {
    var sensor = require("node-dht-sensor")    
    sensor.read(11, 4, function(err, temperature, humidity) {
      if (!err) {
        return {temperature: temperature, 
                humidity: humidity,
        };
      }
    });
  },

  getTemperature: function () {
    return this.readFromSensor().temperature;
  },

  getHumidity: function () {
    return this.readFromSensor().humidity;
  },


  socketNotificationReceived: function(notification) {
    switch(notification) {
      case "READ_FROM_SENSOR":
        var payload = (this.getTemperature() + "°C" + " - " + this.getHumidity() + "%");
        this.sendSocketNotification("READ", payload);
        break;
    }
  },
})
</code></pre>
<p dir="auto">With the last one I have tested the read function and it works when run from a separate .js file. I’ve also tested that both modules can display simple string text.</p>
]]></description><link>https://forum.magicmirror.builders/topic/18602/need-help-with-modules-not-displaying</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 18:40:06 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/18602.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Mar 2024 22:04:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Need help with modules not displaying on Tue, 26 Mar 2024 07:43:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/illimar" aria-label="Profile: Illimar">@<bdi>Illimar</bdi></a> said in <a href="/post/116583">Need help with modules not displaying</a>:</p>
<p dir="auto"><code>getDaysLeft()</code> and <code>dateFormat()</code> are defined as member methods of the module, but you are using them as general functions.</p>
<pre><code class="language-js">var days = getDaysLeft(i);
</code></pre>
<p dir="auto">It should be;</p>
<pre><code class="language-js">var days = this.getDaysLeft(i);
</code></pre>
<p dir="auto">Or, even better is; to define <code>getDaysLeft</code> as a general function inside of <code>getDom()</code>, because only there the function is used once and nowhere else. It doesn’t need to be defined as a member of the module.</p>
<pre><code class="language-js">getDom: function() {
  const getDaysLeft = (i, config) =&gt; {
    const date = Date.now();
    ...
  }
  let wrapper = document.createElement('div');
  wrapper.style.color = this.config.textColor;
  for (let i in this.config.dates) {
    let days = getDaysLeft(i, this.config);
  ...

</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/116596</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/116596</guid><dc:creator><![CDATA[MMRIZE]]></dc:creator><pubDate>Tue, 26 Mar 2024 07:43:11 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with modules not displaying on Mon, 25 Mar 2024 22:42:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/illimar" aria-label="Profile: Illimar">@<bdi>Illimar</bdi></a> open the developers window, ctrl-shift-i</p>
<p dir="auto">select the sources tab, and send the left navigation to you module name</p>
<p dir="auto">the console tab could show errors too.</p>
<p dir="auto">put a unique part of the module name I  the filter field</p>
]]></description><link>https://forum.magicmirror.builders/post/116585</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/116585</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 25 Mar 2024 22:42:46 GMT</pubDate></item><item><title><![CDATA[Reply to Need help with modules not displaying on Mon, 25 Mar 2024 22:39:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/illimar" aria-label="Profile: Illimar">@<bdi>Illimar</bdi></a> the module name, folder, modulename.js AND  the value in the module.register</p>
<pre><code class="language-js">Module.register("days-left"
</code></pre>
<p dir="auto">MUST match exactly.</p>
]]></description><link>https://forum.magicmirror.builders/post/116584</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/116584</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 25 Mar 2024 22:39:58 GMT</pubDate></item></channel></rss>