• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

Head first developing MM module for extreme beginners

Scheduled Pinned Locked Moved Development
27 Posts 9 Posters 19.0k Views 12 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.
  • N Offline
    nrayever @sdetweil
    last edited by Feb 4, 2021, 5:27 PM

    @sdetweil … ok.

    D 1 Reply Last reply Mar 6, 2021, 5:28 PM Reply Quote 0
    • D Offline
      Dobi @nrayever
      last edited by Dobi Mar 6, 2021, 5:29 PM Mar 6, 2021, 5:28 PM

      Hey guys,

      I’m quite new in developing an own module. I was able to change exiting modules on my magic mirror but now I wanted to create my own module, but I’m not able to get socket communication between my “main” module an the “helper-function”

      I uploaded my module here:
      https://github.com/Dobherrmann/MMM_Testmodul.git
      my Module looks like this on my magic mirror:
      8f60324c-9269-4d1c-b5ae-0e337b316361-grafik.png
      maybe someone can find my mistake(s).

      BR

      S 1 Reply Last reply Mar 6, 2021, 5:49 PM Reply Quote 0
      • S Offline
        sdetweil @Dobi
        last edited by sdetweil Mar 7, 2021, 3:36 PM Mar 6, 2021, 5:49 PM

        @dobi two things

        when the DomObject Created method is called, its POSSIBLE that the elements are not yet accessible… so your code fails as the document.getElementbyID returns null…

        second, do you have a position: set in the module def in config.js?

        third and MOST important

        the module NAME must match the folder name AND the filename and the register in the file…

        so, the filename is MMM-cookbook.js
        therefore ALL the things must be called MMM-cookbook

        git clone will name the folder the name of the github repo
        (unless u add an extra part to git clone repo_url output_folder_name)

        I fixed all those and the module displays the countdown/up each second

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        D 1 Reply Last reply Mar 7, 2021, 3:16 PM Reply Quote 0
        • D Offline
          Dobi @sdetweil
          last edited by Mar 7, 2021, 3:16 PM

          @sdetweil ahh thank you for these information I will give it a try.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dobi
            last edited by Mar 7, 2021, 5:34 PM

            @sdetweil I gave it a try but without differences :(
            I made a new git repo : https://github.com/Dobherrmann/MMM-cookbook.git
            Now there I should have the same name in the repo like my module.

            my config. js looks like this (I gave it a position):

             {
                  module: "MMM-cookbook",
                  position: "middle_center",
                  config: {
                    header: "My Cookbook",
                    foo: "I'm the King of the world!"
                  }
                },
            

            I started to debug “my code” a little bit and I found this when I want to send a socket notification:

            self.sendSocketNotification("DO_YOUR_JOB", this.count);
            					console.log("Notfication", this.sendSocketNotification("DO_YOUR_JOB", this.count))
            					this.sendSocketNotification("DO_YOUR_JOB", this.count)
            					this.subElementUp.innerHTML = "Count UP:" + this.count
            

            On my console i get the feedback that “this.sendSocketNotification(“DO_YOUR_JOB”, this.count” is undefined. It looks like that this function is unkown.

            S 1 Reply Last reply Mar 7, 2021, 5:48 PM Reply Quote 0
            • S Offline
              sdetweil @Dobi
              last edited by sdetweil Mar 7, 2021, 5:51 PM Mar 7, 2021, 5:48 PM

              @dobi u are inside a callback. change the ‘this’ to ‘self’ like the self.sendSocketNotification

              ‘this’ is always tricky. depends on the context, and some of the programming idioms used

              that’s why we typically see
              var self = this;
              at the beginning of functions that have callbacks or .then() used inside

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              D 1 Reply Last reply Mar 7, 2021, 5:54 PM Reply Quote 0
              • D Offline
                Dobi @sdetweil
                last edited by Mar 7, 2021, 5:54 PM

                @sdetweil ok, but it dosen’t change something.

                notificationReceived: function (notification, payload, sender) {
                		self = this;
                		switch (notification) {
                			case "DOM_OBJECTS_CREATED":
                				var timer = setInterval(() => {
                					//this.updateDom()
                					self.sendSocketNotification("DO_YOUR_JOB", this.count);
                					console.log(`self.sendSocketNotification("DO_YOUR_JOB", this.count)`, self.sendSocketNotification("DO_YOUR_JOB", this.count))
                					self.sendSocketNotification("DO_YOUR_JOB", this.count)
                					this.subElementUp.innerHTML = "Count UP:" + this.count
                					this.count++
                				}, 1000)
                				break
                		}
                	},
                

                Now i could post a picture of my console
                875c1b85-daa2-4374-b4d3-c833268e7387-grafik.png

                S 2 Replies Last reply Mar 7, 2021, 5:57 PM Reply Quote 0
                • S Offline
                  sdetweil @Dobi
                  last edited by sdetweil Mar 7, 2021, 5:58 PM Mar 7, 2021, 5:57 PM

                  @dobi show the source code page. u had to fix both counters

                  sources tab, modules, mmm-cookbook, mmm-cookbook.js

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    sdetweil @Dobi
                    last edited by sdetweil Mar 7, 2021, 6:03 PM Mar 7, 2021, 6:03 PM

                    @dobi

                    self.sendSocketNotification("DO_YOUR_JOB", this.count)
                    

                    but u didn’t change this.count to self.count
                    in all the places

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    D 1 Reply Last reply Mar 7, 2021, 7:29 PM Reply Quote 0
                    • D Offline
                      Dobi @sdetweil
                      last edited by Mar 7, 2021, 7:29 PM

                      @sdetweil I replaced all this. … calls to self. … but I don’t get a change. Is there a way that I can check to check that I can check that the function is loaded correctly from the kernal?

                      S 1 Reply Last reply Mar 7, 2021, 7:44 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 2 / 3
                      • 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