• 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.

Even a simple node_help.js example does not run.

Scheduled Pinned Locked Moved Unsolved Troubleshooting
13 Posts 2 Posters 2.5k 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.
  • E Offline
    emrhssla
    last edited by Apr 12, 2019, 9:29 AM

    MMM-Testpython

    var Testpythons;
    Module.register("MMM-Testpython", {
    
        defaults: {},
        start: function (){
            Testpythons = this;
        },
      
      getDom: function() {
        var element = document.createElement("div")
        element.className = "myContent"
        element.id="divid"
        element.innerHTML = "Hello, World!!! " + this.config.foo
        var subElement = document.createElement("p")
        subElement.innerHTML = "Click" 
        subElement.id = "clickid"
        element.appendChild(subElement)
        return element
      },
      
      notificationReceived: function(notification, payload, sender) {
        switch(notification) {
          case "DOM_OBJECTS_CREATED":
          var elem = document.getElementById("clickid")
          elem.addEventListener("click", () => {
            Testpythons.sendSocketNotification("TEST")
            console.log("hello~hello~hello~hello~hello~hello~hello~hello~hello~hello~")
            elem.innerHTML = "click success"       
          }) 
            break
        }
      },
      
    })
    

    node_helper.js

    var NodeHelper = require("node_helper");
    var {PythonShell} = require('python-shell');
    
    module.exports = NodeHelper.create({
      start: function() {},
      
      socketNotificationReceived: function(notification, payload) {
        switch(notification) {
          case "TEST":
            console.log("notification : " + notification)
            this.sendSocketNotification("I_DID")
            break
        }
      },
    })  
    

    0_1555061178870_43ed7384-d4d5-4421-8c6b-a664582b6883-image.png
    0_1555061131673_64d4b79c-9344-4c93-9f4f-31ed55371eca-image.png
    The notification I_DID in node_helper.js was well communicated and executed. However, the console in node_helper.js is not output…
    What is the problem?

    var NodeHelper = require("node_helper");
    var {PythonShell} = require('python-shell');
    
    module.exports = NodeHelper.create({
      start: function() {},
      
      socketNotificationReceived: function(notification, payload) {
        Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
        
      },
    })  
    

    0_1555061311849_80e6e224-4ff0-45e5-89e5-93ad49f7cc0d-image.png

    0_1555061325787_4d1587ba-527f-4a4c-92c0-8c5c5b1dbff7-image.png

    Even a simple node_help.js example does not run.

    1 Reply Last reply Reply Quote 0
    • S Away
      sdetweil
      last edited by Apr 12, 2019, 12:13 PM

      @emrhssla said in Even a simple node_help.js example does not run.:

      Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);

      as I posted in the other topic, the node_helper content would be displayed in the terminal window
      where u started MM…

      also

      Log.log will not work in node helper. that is only available in the module.js

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil
        last edited by sdetweil Apr 12, 2019, 12:33 PM Apr 12, 2019, 12:32 PM

        @emrhssla said in Even a simple node_help.js example does not run.:

        also, you need to install the python-shell component…

        need a package.json file

        {
          "name": "MMM-Testpython",
          "description": "sample",
          "version": "0.0.1",
          "dependencies": {
            "python-shell": "latest"
          }
        }
        

        and then run

        npm install
        

        in the module folder

        the updated node_helper.js is

        var NodeHelper = require("node_helper");
        var {PythonShell} = require('python-shell');
        
        module.exports = NodeHelper.create({
          start: function() {},
          
          socketNotificationReceived: function(notification, payload) {
            console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
            
          },
        })
        

        and produces this message in the terminal window, when the UI component is clicked

        MMM-Testpython received a socket notification: TEST - Payload: [object Object]
        

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        E 2 Replies Last reply Apr 12, 2019, 1:18 PM Reply Quote 0
        • E Offline
          emrhssla @sdetweil
          last edited by Apr 12, 2019, 1:18 PM

          @sdetweil 0_1555074987553_d58a7d49-677c-4048-a9e4-709a574bc29a-image.png

          Is it normal for these errors to occur?
          /modules/MMM-Testpython/package.json

          S 1 Reply Last reply Apr 12, 2019, 1:27 PM Reply Quote 0
          • E Offline
            emrhssla @sdetweil
            last edited by Apr 12, 2019, 1:26 PM

            @sdetweil said in Even a simple node_help.js example does not run.:

            console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);

            var NodeHelper = require("node_helper");
            //var {PythonShell} = require('python-shell');
            
            module.exports = NodeHelper.create({
              start: function() {},
              
              socketNotificationReceived: function(notification, payload) {
                console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
              },
            })   
            

            0_1555075600760_f2b5f62a-75bc-48ea-9a97-7c88d676b3d5-image.png
            omg…

            S 1 Reply Last reply Apr 12, 2019, 1:28 PM Reply Quote 0
            • S Away
              sdetweil @emrhssla
              last edited by Apr 12, 2019, 1:27 PM

              @emrhssla sorry, I had a name of “sample” when I did it. I guess the - is not allowed

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              E 1 Reply Last reply Apr 12, 2019, 1:46 PM Reply Quote 0
              • S Away
                sdetweil @emrhssla
                last edited by sdetweil Apr 12, 2019, 1:29 PM Apr 12, 2019, 1:28 PM

                @emrhssla that log is only from the module file. Not node_helper

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • E Offline
                  emrhssla @sdetweil
                  last edited by emrhssla Apr 12, 2019, 1:56 PM Apr 12, 2019, 1:46 PM

                  @sdetweil

                  {
                    "name": "MMMTestpython",
                    "description": "samples",
                    "version": "0.0.1",
                    "dependencies": {
                      "python-shell": "latest"
                    }
                  }
                  
                  

                  Do I have to change it like this and install it again? npm install

                  0_1555077390063_231c85f3-9d06-4cd8-a2ec-fa08f4db34ee-image.png

                  S 1 Reply Last reply Apr 12, 2019, 2:18 PM Reply Quote 0
                  • S Away
                    sdetweil @emrhssla
                    last edited by Apr 12, 2019, 2:18 PM

                    @emrhssla I don’t understand… mine worked perfectly

                    package.json

                    {
                      "name": "MMM-Testpython",
                      "description": "sample",
                      "keywords": [
                        "   none"
                      ],
                      "version": "0.0.1",
                      "dependencies": {
                        "python-shell": "latest"
                      }
                    }
                    
                    /MagicMirror/modules/MMM-Testpython$ npm install
                    npm WARN MMM-Testpython@0.0.1 No repository field.
                    npm WARN MMM-Testpython@0.0.1 No license field.
                    
                    added 1 package from 1 contributor and audited 1 package in 0.821s
                    found 0 vulnerabilities
                    
                    odroid@odroid:~/MagicMirror/modules/MMM-Testpython$
                    

                    what version of npm do you have

                    npm -v

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    E 2 Replies Last reply Apr 12, 2019, 2:45 PM Reply Quote 0
                    • E Offline
                      emrhssla @sdetweil
                      last edited by Apr 12, 2019, 2:45 PM

                      This post is deleted!
                      S 1 Reply Last reply Apr 12, 2019, 2:47 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        1/13
                        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