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

MMM-PIR-Sensor execute .py script



  • Goal: Execute .py using MMM-Pir-Sensor

    Hi all, I’m having trouble executing a .py script that sits in the directory:

    /home/pi/Documents/test.py

    According to @orayoflighto in this thread, he suggests adding 1 line to node_helper.js that sits in the MMM-PIR-Sensor module directory from:

            if (data.indexOf("0x120002") !== -1)
              exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
    

    to

            if (data.indexOf("0x120002") !== -1){
              exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null);
              exec("python /home/pi/py-spidev/RPi-LPD8806/LED.py");
           }
    

    I’ve tried this exec() below in both activateMonitor and briefHDMIWakeup function and it’s not working.

        briefHDMIWakeup: function() {
            const self = this
            exec("/usr/bin/vcgencmd display_power").stdout.on('data', function(data) {
                if (data.indexOf("display_power=0") === 0) {
                    exec("/usr/bin/vcgencmd display_power 1", null);
                    exec("python /home/pi/Documents/test.py")
    

    Note, calling sudo python3 test.py in cmd line works itself. I’m having trouble figuring out why exec() is not calling in node_helper.js. Any tips on debugging this?

    I tried console.log(text); in .js file. It’s not calling either (i may be totally viewing command prompt wrong to view debug message)

    Thanks for reading!



  • MMM-PIR-Sensor by paviro node_helper.js txt here


Log in to reply