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.

    Add JS Code to the Mirror

    Scheduled Pinned Locked Moved Solved Troubleshooting
    33 Posts 5 Posters 15.4k Views 5 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.
    • S Offline
      stro
      last edited by

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • S Offline
        stro
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • S Do not disturb
          sdetweil
          last edited by

          So, u need to change the HTML returned by MMM-MPD to look like the HTML in the file. But only the section that is your real user interface.

          See the getDom() function which would build the html.

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • S Offline
            stro
            last edited by

            No, i want to show the current playing Track from mopidy.

            Either by MMM-MPD (i didn‘t get to work)
            Or by the Code i found on the web ( i didn‘t get to work)

            S 1 Reply Last reply Reply Quote 0
            • S Do not disturb
              sdetweil @stro
              last edited by

              @stro MagicMirror is a web page.
              It displays html. The modules generate a small section matching their requirements, and mm injects that onto the page in the configured position.

              The module can get it’s data from anywhere. API, file system, database.

              You have an API, which returns data, not html. Some code has to convert the data into displayable html

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 1
              • S Offline
                stro
                last edited by

                @sdetweil thanks for helping me.

                I have the code (pastebin) who put the data, i‘m looking for, in a HTML Output. If i open the html file like this

                file:///home/pi/MagicMirror/modules/test/mopidy.html
                

                everything is okay.

                But if open this HTML File with the Mirrorpath like this:

                localhost:8080/modules/test/mopidy.html
                

                It shows me nothing. And i wonder why.

                S 1 Reply Last reply Reply Quote 0
                • S Do not disturb
                  sdetweil @stro
                  last edited by

                  @stro open the developers window, ctrl-shift-i, select the console tab and scroll up to see any errors

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    stacywebb
                    last edited by

                    Check your

                    mopidy.conf

                    located at:

                    ~/.config/mopidy/mopidy.conf
                    

                    Look for this section:

                    [http]
                    enabled = true
                    hostname = 127.0.0.1
                    port = 6680
                    static_dir =
                    zeroconf = Mopidy HTTP server on $hostname
                    allowed_origins =
                    csrf_protection = true
                    

                    Take note of the hostname part.
                    If your’s looks like the above instead of using localhost in the url, use the ip address or host name of the mirror.

                    Examples:
                    mirror.local:8080/modules/test/mopidy.html
                    or
                    10.x.x.x:8080/modules/test/mopidy.html

                    I tested the code you posted on pastebin and it works as expected for me.
                    Only tested using the hostname of the Mirror from external browser. Not locally on the machine.

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      stro
                      last edited by stro

                      I was able to solve that problem.
                      MPD port was double busy. Apparently 2 instances of Mopidy were running.

                      Now the module MMM-MPD runs under a few specials:

                      During the installation the folder name has to be changed according to the config file.
                      The config file value maxRows must not be 0!
                      The display will only update after a song change!

                      It was hard to find this specifics, but I thank everyone for the help!

                      1 Reply Last reply Reply Quote 0
                      • L Offline
                        Leobo
                        last edited by

                        Thank You @stro, This work great. Im rename folder MMM-MPD to mod_client and move to MagicMirror module, From MagicMirror/module/mpd_client npm install and work.

                        D 1 Reply Last reply Reply Quote 0
                        • D Offline
                          dnj0104 @Leobo
                          last edited by

                          @Leobo said in Add JS Code to the Mirror:

                          Thank You @stro, This work great. Im rename folder MMM-MPD to mod_client and move to MagicMirror module, From MagicMirror/module/mpd_client npm install and work.

                          Something like this happens to me, but my module is from user coderpussy @github , pretty new fork, maybe I got some failure from moodeaudio devs, but I dont think, so anyway here is some of my errors.

                          if change folder name mmm-mpd to mpd_client errors in MM startup:
                          
                          alerts in MagicMirror startup:
                          WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: ReferenceError: NodeHelper is not defined
                              at Object.<anonymous> (/home/pi/MagicMirror/modules/mpd_client/node_helper.js:4:18)
                              at Module._compile (internal/modules/cjs/loader.js:786:30)
                              at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
                              at Module.load (internal/modules/cjs/loader.js:645:32)
                              at Function.Module._load (internal/modules/cjs/loader.js:560:12)
                              at Module.require (internal/modules/cjs/loader.js:685:19)
                              at require (internal/modules/cjs/helpers.js:16:16)
                              at loadModule (/home/pi/MagicMirror/js/app.js:134:17)
                              at loadNextModule (/home/pi/MagicMirror/js/app.js:169:5)
                              at /home/pi/MagicMirror/js/app.js:171:6
                          
                          change folder name from mmm-mpd to mpd-client:
                          Result: No errors in MM-startup but mpd-module does not start.
                          
                          **Looking for errors in MM-dev tools with folder named to mpd-module>** 
                          
                          Errors:
                          Load script: modules/mpd_client//mpd_client.js
                          :8080/modules/mpd_cl…nt//mpd_client.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
                          loader.js:186 Error on loading script: modules/mpd_client//mpd_client.js
                          
                          
                          module in mm-config array looks like 
                          this.
                          
                          {
                          		module: "mpd_client",
                          		position: "top_right",	// This can be any of the regions.
                          		config: {
                          			  // See 'Configuration options' for more information.
                          			hostname:"mpd@moodeaudio@rpi3b+=IPnumber)",
                          			port:6600 
                          			
                          		}
                                  
                               },    
                          
                          
                          S 1 Reply Last reply Reply Quote 0
                          • S Do not disturb
                            sdetweil @dnj0104
                            last edited by

                            @dnj0104 there is probably more to the error message this also happens when there is some library required by a module not found at startup

                            u can also run

                            npm run config:check 
                            

                            to review any syntax errors in the config.js file

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            D 1 Reply Last reply Reply Quote 0
                            • D Offline
                              dnj0104 @sdetweil
                              last edited by

                              @sdetweil said in Add JS Code to the Mirror:

                              npm run config:check

                              in magicmirror/modules

                              or in magicmirror/modules/mpd-module ?

                              Thinks the whole module has to be rebuilt…

                              S 1 Reply Last reply Reply Quote 0
                              • S Do not disturb
                                sdetweil @dnj0104
                                last edited by

                                @dnj0104 in MagicMirror

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                D 1 Reply Last reply Reply Quote 0
                                • D Offline
                                  dnj0104 @sdetweil
                                  last edited by

                                  @sdetweil

                                  then I got

                                  [2020-10-23 23:46:08.836] [INFO]   Checking file...  /home/pi/MagicMirror/config/config.js
                                  [2020-10-23 23:46:09.049] [INFO]   Your configuration file doesn't contain syntax errors :)
                                  
                                  S 1 Reply Last reply Reply Quote 0
                                  • S Do not disturb
                                    sdetweil @dnj0104
                                    last edited by sdetweil

                                    @dnj0104 ok, so the error that causes the default config to load is caused by some other problem.

                                    missing module, or some other failure

                                    can u show the MM startup messages (from the window where you do npm start)

                                    a module consists of the folder name

                                    MMM-MPD
                                    

                                    and its main js file

                                    MMM-MPD.js
                                    

                                    and inside MMM-MPD.js is the module register statement

                                    Module.register("MMM-MPD", {
                                    

                                    and in config.js

                                      {
                                         module: 'MMM-MPD',
                                    

                                    this causes MM to look for the folder, filename and file contents in that order

                                    SO, it SOUNDS like from a prior post, that the REAL name is

                                    mod_client
                                    

                                    (so there must be the right folder name, file name and file contents of
                                    mod_client

                                    if so, you can rename the folder (mv is the rename command on linux)
                                    then in config.js you need

                                      module:'mod_client',
                                    

                                    see the topic ‘How to add modules’ in my signature

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      dnj0104
                                      last edited by

                                      @sdetweil said in Add JS Code to the Mirror:

                                      mod_client

                                      errors folder and file config.js (mmm-mpd) renamed to mod:

                                      [2020-10-24 00:03:42.600] [ERROR]  WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: ReferenceError: NodeHelper is not defined
                                          at Object.<anonymous> (/home/pi/MagicMirror/modules/mod_client/node_helper.js:4:18)
                                          at Module._compile (internal/modules/cjs/loader.js:786:30)
                                          at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
                                          at Module.load (internal/modules/cjs/loader.js:645:32)
                                          at Function.Module._load (internal/modules/cjs/loader.js:560:12)
                                          at Module.require (internal/modules/cjs/loader.js:685:19)
                                          at require (internal/modules/cjs/helpers.js:16:16)
                                          at loadModule (/home/pi/MagicMirror/js/app.js:134:17)
                                          at loadNextModule (/home/pi/MagicMirror/js/app.js:169:5)
                                          at /home/pi/MagicMirror/js/app.js:171:6
                                      [2020-10-24 00:03:42.601] [LOG]    Loading module helpers ...
                                      [2020-10-24 00:03:42.602] [LOG]    No helper found for module: alert.
                                      [2020-10-24 00:03:42.603] [LOG]    Initializing new module helper ...
                                      [2020-10-24 00:03:42.604] [LOG]    Module helper loaded: updatenotification
                                      [2020-10-24 00:03:42.605] [LOG]    No helper found for module: clock.
                                      [2020-10-24 00:03:42.616] [LOG]    Initializing new module helper ...
                                      [2020-10-24 00:03:42.617] [LOG]    Module helper loaded: calendar
                                      [2020-10-24 00:03:42.618] [LOG]    No helper found for module: .
                                      [2020-10-24 00:03:42.619] [LOG]    No helper found for module: currentweather.
                                      [2020-10-24 00:03:42.620] [LOG]    No helper found for module: weatherforecast.
                                      [2020-10-24 00:03:42.621] [LOG]    Initializing new module helper ...
                                      [2020-10-24 00:03:42.621] [LOG]    Module helper loaded: newsfeed
                                      [2020-10-24 00:03:42.623] [ERROR]  App threw an error during load
                                      [2020-10-24 00:03:42.625] [ERROR]  ReferenceError: NodeHelper is not defined
                                          at Object.<anonymous> (/home/pi/MagicMirror/modules/mod_client/node_helper.js:4:18)
                                          at Module._compile (internal/modules/cjs/loader.js:786:30)
                                          at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
                                          at Module.load (internal/modules/cjs/loader.js:645:32)
                                          at Function.Module._load (internal/modules/cjs/loader.js:560:12)
                                          at Module.require (internal/modules/cjs/loader.js:685:19)
                                          at require (internal/modules/cjs/helpers.js:16:16)
                                          at loadModule (/home/pi/MagicMirror/js/app.js:134:17)
                                          at loadNextModule (/home/pi/MagicMirror/js/app.js:169:5)
                                          at /home/pi/MagicMirror/js/app.js:171:6
                                      [2020-10-24 00:03:42.627] [ERROR]  Whoops! There was an uncaught exception...
                                      [2020-10-24 00:03:42.628] [ERROR]  ReferenceError: NodeHelper is not defined
                                          at Object.<anonymous> (/home/pi/MagicMirror/modules/mod_client/node_helper.js:4:18)
                                          at Module._compile (internal/modules/cjs/loader.js:786:30)
                                      

                                      ------result---- dark—screen electron just showed black----------

                                      roll back, Folder named to mod-client and in config.js and mpd_client.js to mod_client.
                                      Result; electron start with no error all my modules shows, but not mod_client aka mpd_client

                                      S 1 Reply Last reply Reply Quote 0
                                      • S Do not disturb
                                        sdetweil @dnj0104
                                        last edited by

                                        @dnj0104 what MM version are you running on? this problem was fixed in 2.10
                                        do this
                                        from the MM folder

                                        cd ~/MagicMirror
                                        git checkout modules/node_modules/node_helper/index.js
                                        

                                        Sam

                                        How to add modules

                                        learning how to use browser developers window for css changes

                                        1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          dnj0104
                                          last edited by

                                          I got version 20.13.0

                                          from your git command i get output

                                          pi@raspberrypi:~/MagicMirror $ git checkout modules/node_modules/node_helper/index.js
                                          error: pathspec 'modules/node_modules/node_helper/index.js' did not match any file(s) known to git
                                          
                                          S 1 Reply Last reply Reply Quote 0
                                          • S Do not disturb
                                            sdetweil @dnj0104
                                            last edited by

                                            @dnj0104 can you do

                                            cd ~/MagicMirror
                                            grep version package.json
                                            

                                            Sam

                                            How to add modules

                                            learning how to use browser developers window for css changes

                                            S 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
                                            • 2
                                            • 2 / 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