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.

    error loop

    Scheduled Pinned Locked Moved Development
    11 Posts 3 Posters 3.6k Views 3 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.
    • J Offline
      jchenaud
      last edited by

      first of all hello :)

      i make my module and i have 2 looping error but she is not located on my code
      alt text

      do you have idea?
      thk for your attention

      1 Reply Last reply Reply Quote 0
      • D Offline
        doubleT Module Developer
        last edited by

        Well, the error information are pretty clear, you just need to look at your code to come to a conclusion. Without seeing the code, we can’t know anything about why these errors occur.

        1st says there’s no element by the class name you’re searching for. Either it’s not there or you’re looking in the wrong place.

        2nd says you’re trying to append something that is not an element. You can’t append a string, for example.

        For example, that’s a string and won’t work:

        let parent = document.getElementById("parent");
        let element = "<div>lorem ipsum</div>";
        parent.appendChild(element);
        

        This will work:

        let parent = document.getElementById("parent");
        let element = document.createElement("div");
        element.innerHTML = "lorem ipsum";
        parent.appendChild(element);
        
        J 1 Reply Last reply Reply Quote 1
        • J Offline
          jchenaud @doubleT
          last edited by

          @doublet
          i am not sure to understand

          if i remove my module i have one error (i correct after if i can)

          but the looping are ok

          my module

          Module.register("MMM-keylogger",{
          	curentPage: -1,
          	defaults: {
          		updateInterval:  1000,
          	},
          
          	start: function(){
                  console.log(this.name + " has started...!!!!!!");
          		this.sendSocketNotification("START", this.config);
          	},
          
          	socketNotificationReceived: function(notification, payload) {
          		if(notification === "KEY_P"){
          			this.dataFile = payload;
          			this.updateDom();
                  }
          	},
          
          	getDom: function(){
          		var wrapper = document.createElement("div");
          		wrapper.innerHTML = this.dataFile
          			if(this.dataFile){
          				switch(wrapper.innerHTML) {
          					case "Right":
          					this.sendNotification("PAGE_INCREMENT");
          						break;
          					case "Left" :
          					this.sendNotification("PAGE_DECREMENT");
          						break;
          					default:
          					Log.log(`key : ${wrapper.innerHTML} pressed but not assigned`);
          				}
          				this.sendSocketNotification("Clear_key")
          			}
          			return wrapper;
          	},
          
          });
          
          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);
          		}
          		if(notification === "Clear_key")
          		{
          			fs.open('Key_pres.txt', 'r+', function(err, fd) {
          				if (err) {
          				   return console.error(err);
          				}
          				fs.ftruncate(fd, function(err){
          					if (err){
          					   console.log(err);
          					}
          					console.log("supose to trucate");
          				})
          			});
          	}
          	},
          
          	readData: function(){
          		fs.readFile("Key_pres.txt", "utf8", (err, data) => {
          			if (err) throw err;
          		   this.sendSocketNotification("KEY_P", data);
             })		
          	}
          });
          

          i have no warning of no declare class or something like that on VS

          sorry but i beginner with organisation of MM

          thanks for your rapidity :)

          1 Reply Last reply Reply Quote 0
          • ? Offline
            A Former User
            last edited by

            Have you assigned proper position for that module in config.js?

            1 Reply Last reply Reply Quote 0
            • J Offline
              jchenaud
              last edited by

              @Sean

              thanks you have suppress the first error on screen-shot
              but my modul write something on screen and i don’t want that but its can be cool for debug

              ? 1 Reply Last reply Reply Quote 0
              • ? Offline
                A Former User @jchenaud
                last edited by A Former User

                @jchenaud
                If your module doesn’t need to possess area in MagicMirror (even your module would draw something on MM), you wouldn’t use .getDom(). That function should be called by MM.core when the refreshing screen is needed. but your .getDom() will not work properly because there is no position to be drawn on.
                So you should assign a position to use .getDom().
                (Of course, there is some trick without .getDom() and position to draw something on MM)

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jchenaud @Guest
                  last edited by

                  @sean
                  thk for explain. i will try something different to get.getDom().

                  have you an idea for appendChild error ?

                  ? 1 Reply Last reply Reply Quote 0
                  • ? Offline
                    A Former User @jchenaud
                    last edited by A Former User

                    @jchenaud I think that is also caused by unproper using of .getDom()
                    Better practice is;

                    1. use .getDom() with proper position
                    2. or, not using .getDom().
                    • You can start to manipulate your DOM when DOM_OBJECTS_CREATED notification from MM Core.
                      like these;
                    notificationReceived: function(noti, payload, sender) {
                      switch(noti) {
                        case 'DOM_OBJECTS_CREATED':
                          this.initMyDOM()
                          break
                      }
                    },
                    initMyDOM: function() {
                      var wrapper = document.createElement("div")
                      wrapper.id = "myDOM"
                      var container = document.body
                      container.appendChild(wrapper)
                      
                     var timer = setInterval(()=>{
                      var d = document.getElementById("myDOM")
                      d.innerHTML = "This is rendered without getDom and position"
                      }, 1000)
                    }
                    
                    

                    This is not tested on real device, but you can catch the idea.

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      jchenaud
                      last edited by

                      thk i will try :)

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        jchenaud
                        last edited by

                        @Sean you are awesome !!!
                        my module almost work

                        just one problem i need to give a position in config. i think i have miss something

                        Module.register("MMM-keylogger",{
                        	defaults: {
                        		 updateInterval:  1500,
                        	},
                        
                        	notificationReceived: function(noti, payload, sender) {
                        		Log.log(`notif : ${noti}`);
                        		switch(noti) {
                        		  case 'MODULE_DOM_CREATED':
                        			this.initMyDOM()
                        			break
                        		}
                        	  },
                        	  initMyDOM: function() {
                        		var wrapper = document.createElement("div")
                        		wrapper.id = "myDOM"
                        		var container = document.body
                        		container.appendChild(wrapper)
                        		Log.log(`init DOM `);
                        		var timer = setInterval(()=>{
                        			var d = document.getElementById("myDOM")
                        			d.innerHTML =  this.dataFile
                        		Log.log(`key : ${d.innerHTML} , ${this.dataFile} `);
                        			if(d.innerHTML){
                        				switch(d.innerHTML) {
                        					case "Right":
                        					this.sendNotification("PAGE_INCREMENT");
                        						break;
                        					case "Left" :
                        					this.sendNotification("PAGE_DECREMENT");
                        						break;
                        					default:
                        					Log.log(`key : ${d.innerHTML} pressed but not assigned`);
                        				}
                        				this.sendSocketNotification("Clear_key")
                        			}
                        			
                        			}, 1500)
                        	},
                        
                        	start: function(){
                                console.log(this.name + " has started...!!!!!!");
                        		this.sendSocketNotification("START", this.config);
                        	},
                        
                        	socketNotificationReceived: function(notification, payload) {
                        		if(notification === "KEY_P"){
                        			this.dataFile = payload;
                        			// this.updateDom();
                                }
                        	},
                        

                        if i don’t give position on config its don’t work ! if i have understand what you have say. this is suppose to work

                        other question : one of my other module have subitly stop to work and make same error but in this module in need position and update with Miror display. so my question is : this is possible this modification have impact on other module ?

                        ? 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • 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