MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    txt-file-include doesn´t work

    Scheduled Pinned Locked Moved Troubleshooting
    txtfileinclude
    4 Posts 2 Posters 2.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      k3rn3lpanic
      last edited by

      Re: .txt file include

      Hi strawberry 3.141,
      i´ve read your interesting threat with regard to including textfiles.

      Your posted solution doesn´t work for me, and im searching why and i don´t find any failure…

      MMM-OEBBv2.js:

      Module.register("MMM-OEBBv2",{
              defaults: {
                      updateInterval: 30 * 60 * 1000 //reads the file every 30 mins
              },
      
              start: function(){
                      this.sendSocketNotification("START", this.config);
              },
      
              socketNotificationReceived: function(notification, payload) {
                      if(notification === "DATA"){
                              this.dataFile = payload;
                              this.updateDom();
                      }
              },
      
              getDom: function(){
                      var wrapper = document.createElement("div");
                      if(this.dataFile){
                              wrapper.innerHTML = this.dataFile;
                      } else {
                              wrapper.innerHTML = "No Data!";
                      }
                      return wrapper;
              }
      });
      

      node-helper.js:

      const NodeHelper = require("node_helper");
      const fs= require("fs");
      
      module.exports = NodeHelper.create({
      //here comes the part of the nodehelper after the 3 dots as posted above
      
              socketNotificationReceived: function(notification, payload) {
                      if(notification === "START"){
                              this.config = payload;
                              this.readData();
                              setInterval(() => {
                                      this.readData();
                              }, this.config.updateInterval);
                      }
              },
      
              readData: function(){
                      //to read a file to do the following
                      fs.readFile("daten.txt", "utf8", (err, data) => {
                              if (err) throw err;
                              this.sendSocketNotification("DATA", data);
                      });
              }
      });
      

      daten.txt:

      WB 912 um 13:00 von Bahnsteig 6A-C
      S 2 um 13:04 von Bahnsteig 5A-C
      REX 4410 um 13:04 von Bahnsteig 8A-C
      

      On the mirror always “No Data!” is shown.
      Please help me…

      Kind regards

      strawberry 3.141S 1 Reply Last reply Reply Quote 0
      • strawberry 3.141S Offline
        strawberry 3.141 Project Sponsor Module Developer @k3rn3lpanic
        last edited by

        @k3rn3lpanic

        readData: function(){
            fs.readFile("modules/MMM-OEBBv2/daten.txt", "utf8", (err, data) => {
                if (err) throw err;
                this.sendSocketNotification("DATA", data);
            });
         }
        

        Please create a github issue if you need help, so I can keep track

        1 Reply Last reply Reply Quote 0
        • K Offline
          k3rn3lpanic
          last edited by

          @strawberry-3-141 i´ve changed the path in the node-helper.js, but it doesn´t solve my problem…
          Are there any other opportunities?

          const NodeHelper = require("node_helper");
          const fs= require("fs");
          
          module.exports = NodeHelper.create({
          
                  socketNotificationReceived: function(notification, payload) {
                          if(notification === "START"){
                                  this.config = payload;
                                  this.readData();
                                  setInterval(() => {
                                          this.readData();
                                  }, this.config.updateInterval);
                          }
                  },
          
                  readData: function(){
                          fs.readFile("modules/MMM-OEBBv2/daten.txt", "utf8", (err, data) => {
                                  if (err) throw err;
                                  this.sendSocketNotification("DATA", data);
                          });
                  }
          });
          
          

          kind regards
          k3rn3lpanic

          1 Reply Last reply Reply Quote 0
          • strawberry 3.141S Offline
            strawberry 3.141 Project Sponsor Module Developer
            last edited by

            problem was he named node_helper.js as node-helper.js

            Please create a github issue if you need help, so I can keep track

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post
            Enjoying MagicMirror? Please consider a donation!
            MagicMirror created by Michael Teeuw.
            Forum managed by Sam, technical setup by Karsten.
            This forum is using NodeBB as its core | Contributors
            Contact | Privacy Policy