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

MMM-PIR js error

Scheduled Pinned Locked Moved Unsolved Troubleshooting
2 Posts 1 Posters 596 Views 1 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.
  • U Offline
    uok825
    last edited by Dec 19, 2021, 9:22 PM

    Here is error log:

    0|run-star | [17.11.2021 14:03.06.696] [ERROR] Whoops! There was an uncaught exception...
    0|run-star | [17.11.2021 14:03.06.782] [ERROR] TypeError: Cannot read property 'callbackScripts' of undefined
    0|run-star |     at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-PIR/node_helper.js:37:45)
    0|run-star |     at Socket.socket.on (/home/pi/MagicMirror/js/node_helper.js:109:11)
    0|run-star |     at Socket.emit (events.js:198:13)
    0|run-star |     at Socket.emitUntyped (/home/pi/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22)
    0|run-star |     at process.nextTick (/home/pi/MagicMirror/node_modules/socket.io/dist/socket.js:428:39)
    0|run-star |     at process._tickCallback (internal/process/next_tick.js:61:11)
    

    Here is my node_helper.js

    var NodeHelper = require("node_helper");
    const exec = require('child_process').exec;
    const fs = require('fs');
    const Gpio = require('onoff').Gpio;
    
    var commandDict = {
        "js": "node",
        "py": "python",
        "sh": "sh"
    };
    
    module.exports = NodeHelper.create({
    
        running: false,
    
        socketNotificationReceived: function (notification, payload) {
            const self = this;
            if (notification === "CONFIG") {
                this.config = payload;
                this.pir = new Gpio(this.config.sensorPin, 'in', 'both');
    
                this.pir.watch(function (err, value) {
                    if (value == 1) {
                        self.sendSocketNotification("USER_PRESENCE", true);
                        if (!self.running) {
                            self.running = true;
                            if (self.config.turnOffDisplay) {
                                execute(buildCommand("/default/ac.py"), function (stdout) {
                                    console.log(stdout);
                                });
                            }
                        }
                    }
                });
            } else if (notification === "TIMER_EXPIRED") {
                self.running = false;
                for (var i = 0; i < this.config.callbackScripts.length; i++) {
                    execute(buildCommand(this.config.callbackScripts[i]), function (stdout) {
                        console.log(stdout);
                    });
                }
                if (self.config.turnOffDisplay) {
                    execute(buildCommand("/default/kapat.py"), function (stdout) {
                        console.log(stdout);
                    });
                }
            }
        },
    
    
    });
    
    function buildCommand(fileName) {
        var file = __dirname + "/callbackScripts/" + fileName;
        var fileExtension = file.split(".").slice(-1).pop();
        return commandDict[fileExtension] + " " + file;
    }
    
    function execute(command, callback) {
        exec(command, function (error, stdout, stderr) {
            if (error) {
                console.log(stderr);
            } else {
                callback(stdout);
            }
        });
    }
    
    
    U 1 Reply Last reply Dec 20, 2021, 8:51 PM Reply Quote 0
    • U Offline
      uok825 @uok825
      last edited by Dec 20, 2021, 8:51 PM

      @uok825 Anyone can help? @sdetweil maybe

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