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.

    SleepWake twisted....need help

    Scheduled Pinned Locked Moved Troubleshooting
    3 Posts 2 Posters 474 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.
    • J Offline
      justonemore
      last edited by

      I am trying to use MMM-SleepWake module from sdetweil (real good by the way) to communicate with my own module but can’t figure out what is wrong…everytime MMM-SleepWake wakes, it runs a python program through a function I created in the MMM-SleepWake node_helper file…It runs fine when I uncomment the console.log and comment the sendNotification lines so I know it is working. What I don’t get is how to send the data to my own module…I tried self.sendNotification, this.sendNotification and sendNotification but all of them return an error the function is not defined…how to I send “data” to my MMM-Facez module ?

      Python function included in node_helper from MMM-SleepWake.

      start_python: function() {
          let self = this;
          var py_recog = spawn('python3', ['-u', '/home/pi/MagicMirror/modules/MMM-Facez/recognize.py']);
      
          py_recog.stdout.on('data', function (data) {
      //      console.log(data.toString());
            sendNotification("ATUALIZA_FACEZ", data);
          });
      
          py_recog.stderr.on('data', function(data) {
            console.log('Python returned Error: ', data.toString()); });
      
          py_recog.on('exit', function (code, signal) {
            console.log('Python exited with ' +
                    `code ${code} and signal ${signal}`); });
      
          },		
      

      Error I get :

      [20.05.2021 18:33.47.306] [ERROR] ReferenceError: sendNotification is not defined
          at Socket.<anonymous> (/home/pi/MagicMirror/modules/MMM-SleepWake/node_helper.js:23:7)
          at Socket.emit (events.js:315:20)
          at addChunk (_stream_readable.js:295:12)
          at readableAddChunk (_stream_readable.js:271:9)
          at Socket.Readable.push (_stream_readable.js:212:10)
          at Pipe.onStreamRead (internal/stream_base_commons.js:186:23)
      
      

      my MMM-Facez.js module

      notificationReceived: function(notification, payload, sender) {
        switch(notification) {
          case "ATUALIZA_FACEZ":
            var elem = document.getElementById("TITULO")
            this.nomepessoa = payload
            elem.innerHTML = this.nomepessoa
            break
        }
      },
      
      socketNotificationReceived: function(notification, payload) {
        switch(notification) {
          case "ATUALIZA_FACEZ":
            var elem = document.getElementById("TITULO")
            this.nomepessoa = payload
            elem.innerHTML = this.nomepessoa
            break
        }
      
      S 1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil @justonemore
        last edited by sdetweil

        @justonemore node_helper cannot communicate with any module except its own

        via sendSocketNotification()

        the MODULEname.js can then talk to other modules

        via sendNotification()

        here is a diagram of the design

        module-parts.jpg

        SO, the helper sends the notification up to its module which then forwards it on

        this.sendSocketNotification('send this to others', {notification:ID_of_message_to_other_modules, content: actual_message_content})
        

        MODULEname.js does

         socketNotificationReceived(notice, payload){
             if(notice === 'send this to others')
                 this.sendNotification(payload.notification, payload.content)
        }
        

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          justonemore @sdetweil
          last edited by

          @sdetweil Thank you…

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