MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. ntahlah
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    N
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Groups 0

    ntahlah

    @ntahlah

    0
    Reputation
    89
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    ntahlah Unfollow Follow

    Latest posts made by ntahlah

    • RE: Getting update from python code interval-ly

      @sdetweil oh I see, I made some modification based on your suggestion

      const spawn = require("child_process").spawn
      var NodeHelper = require("node_helper")
      var process = spawn("python", ["/home/pi/MagicMirror/modules/MMM-Attend/attendance.py"])
      require('events').EventEmitter.defaultMaxListeners = 0;
      
      module.exports = NodeHelper.create({
        
        socketNotificationReceived: function(notification, payload){ 
          
        switch(notification) {
              case "GIVE_ME_DATA":
                
                process.stderr.on("data", (data)=>{
                console.log("attend process errorr= "+data)
                })
                process.stdout.on("data", (data)=>{
                  console.log("attend data = "+data)
                  var result = String.fromCharCode.apply(null, new Uint16Array((data)))
                  this.sendSocketNotification("HERE_IS_DATA", result)
                })
              break
          }
        },
      })
      

      is this what you mean based on your previous comment. Because I don’t really get it

      posted in Development
      N
      ntahlah
    • RE: Getting update from python code interval-ly

      @sdetweil ahhh so that seems to be the problem… I thought using

      print("Welcome! \n" + staff_name(int(staff_id)))
      

      is enough to get the output (since I could get the output from print(“No new staff”)).

      Oh in addition, I also got this

      MaxListenersExceededWarning
      

      so I put this

      require('events').EventEmitter.defaultMaxListeners = 0;
      

      inside nodehelper.js (based on my google search) and it seems to run albeitly very slow, well that is something I guess.

      Thanks for the help and advice though.

      posted in Development
      N
      ntahlah
    • RE: Getting update from python code interval-ly

      Hello @sdetweil , thank you for the reply.

      I tried your advice where I use setInterval() in MMM-Attend.js which you could see it here:

      Module.register("MMM-Attend", {
        
        start: function() {
          setInterval(notificationReceived, 1000); //perform every 1000 milliseconds.
          
        },
        
        getDom: function() {
          var e = document.createElement("div")
          e.id = "DISPLAY"
          ///console.log("getDom" + )
          return e
        }, 
        
        notificationReceived: function(notification, payload, sender) {
          this.sendSocketNotification("GIVE_ME_DATA")
          console.log("notificationRecieved")
        },
        socketNotificationReceived: function(notification, payload) {
          switch(notification) {
            case "HERE_IS_DATA":
              var e = document.getElementById("DISPLAY")
              e.innerHTML = payload
              break
          }
        },
        getStyles: function() {
          return ['MMM-Attend.css']
        },
      })
      

      however it gave me error. Is this the way to call it interval-ly? Pardon my Javascript as I really not good at it

      posted in Development
      N
      ntahlah
    • RE: Getting update from python code interval-ly

      Here are the code I used in my module just in case

      MMM-Attend.js

      Module.register("MMM-Attend",{
      	// Default module config.
      	defaults: {
      		updateInterval: 30000,
      		fadespeed: 4000 
      		
      		},
      		
      
       getDom: function() {
          var e = document.createElement("div")
          e.id = "DISPLAY"
          //console.log (test)
          return e
        },
        
       start: function() {
          Log.info('Starting module: ' + this.name);
        },
       
        notificationReceived: function(notification, payload, sender) {
          switch(notification) {
            case "DOM_OBJECTS_CREATED":
              var timer = setInterval(()=>{
                this.sendSocketNotification("GIVE_ME_DATA")
                //var test = "kel"
              }, 1000)
              break
          }
        },
        socketNotificationReceived: function(notification, payload) {
          switch(notification) {
            case "HERE_IS_DATA":
              var e = document.getElementById("DISPLAY")
              e.innerHTML = payload // display nama
      	var timer = setInterval(() =>{
      	    console.log ("e", e.innerHTML)
              }, 1000) 
          }
        },
        getStyles: function() {
            return ['MMM-Attend.css']
        },
        
      })
      

      node_helper.js

      /// node_helper.js
      const spawn = require("child_process").spawn
      var NodeHelper = require("node_helper")
      var process = spawn("python", ["/home/pi/MagicMirror/modules/MMM-Attend/attendance.py"])
      var interval = 1000
      module.exports = NodeHelper.create({
        
        socketNotificationReceived: function(notification, payload) {
          switch(notification) {
            case "GIVE_ME_DATA":
              this.job()
              break
          }
        },
        job: function() {
          process.stdout.on("data", (data)=>{
            //var timer = setInterval(() =>{
      	    console.log ("node_helper", data)
              //}, 1000) 
            var result = String.fromCharCode.apply(null, new Uint16Array((data)))
            this.sendSocketNotification("HERE_IS_DATA", result)
          })    
      
        }
      })
      
      posted in Development
      N
      ntahlah
    • Getting update from python code interval-ly

      Hello everyone!

      I’m currently trying to create a module that can detect a new people who checks in from my finger print using python module that I have created.

      So far, the module already can display in the attendance however it does not update at all which means that I have to restart the Magic mirror in order to get any new person who comes in.

      The python code that I created can update any new attendance interval-ly but somehow it does not show any update on the mirror.

      Here are the GitHub for the module that I’m currently work on: https://github.com/ntahlahweh/MMM-Attend

      Please do assist me on this matter.

      posted in Development
      N
      ntahlah