Read the statement by Michael Teeuw here.
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:
- the timer never starts
- 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('serialDistance.py'); pyshell.on('message', function (message) { console.log(message); self.switchScreenOn(); }); }, switchScreenOff: function(){ console.log("Switch screen off"); clearInterval(timer); }, switchScreenOn: function(){ var self = this; console.log("Switch screens on"); timer = setInterval(self.switchScreenOff, 5000); }, })
-
@jmagsumbol Should the function be simply called
start()
? Doespython_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: https://forum.magicmirror.builders/topic/6291/howto-turn-on-off-your-monitor-time-based-pir-button-app/7
-
@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.