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

node_helper and python communication

  • Hi,

    I have started to dig in developing own modules. I wanted to use an ultrasonic sensor to check if a person is in front of the mirror minimum 100cm. In this case the python script sends a ‘message’ with a type event and distance in cm. This should turn off the screen. Then a timer (5sec) starts to switch off the screen again as long as there is no message coming in.

    I have several problems and don’t know why:

    1. the timer never starts
    2. my console logs are only displayed AFTER the magic mirror app is stopped.

    Can anyone give me a hint? Or is there a better implementation for the communication between python and the modules?

    module.exports = NodeHelper.create({
        python_start: function() {
        		pyshell = new PythonShell('');
        		pyshell.on('message', function (message) {
        switchScreenOff: function(){
        	console.log("Switch screen off");
        switchScreenOn: function(){
        	var self = this;
          console.log("Switch screens on");
        	timer = setInterval(self.switchScreenOff, 5000);

  • @jmagsumbol Should the function be simply called start()? Does python_start() ever get called?

    Alternatively, with a slight modification of MMM-PIR-Sensor, I think this could all be done within Node.js. You’d just need to examine how to handle the GPIO of the ultrasonic sensor in however it differs from a PIR sensor.

    For actually turning the screen off and on, check out @cruunnerr‘s guide:

  • @ninjabreadman yap python_start is called by an event from the modules (script is not complete)
    In the MMM-PIR-Sensor the GPIO is used. In my case I would like to use usb. So i should require node-serial port. That’s what one way I can try it.
    But I also thought of doing the complete logic, like switching on/off the screen, in my python script. So the only job of the module is to call python.

Log in to reply