MagicMirror² v2.8.0 is available! For more information about this release, check out this topic.

Even a simple node_help.js example does not run.



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



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



  • @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]
    


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

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



  • @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…



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



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



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



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



  • This post is deleted!