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

node_helper and python communication

Scheduled Pinned Locked Moved Troubleshooting
3 Posts 2 Posters 1.5k Views 2 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.
  • J Offline
    jmagsumbol
    last edited by Jan 22, 2018, 8:17 PM

    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('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);
        },
    })
    
    N 1 Reply Last reply Jan 23, 2018, 12:31 AM Reply Quote 0
    • N Offline
      ninjabreadman @jmagsumbol
      last edited by Jan 23, 2018, 12:31 AM

      @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: https://forum.magicmirror.builders/topic/6291/howto-turn-on-off-your-monitor-time-based-pir-button-app/7

      Problem with config or JavaScript? Copy/paste it into JSHint.
      Check out the detailed walkthroughs on install, config, modules, etc.

      1 Reply Last reply Reply Quote 0
      • J Offline
        jmagsumbol
        last edited by jmagsumbol Jan 27, 2018, 11:56 PM Jan 27, 2018, 11:55 PM

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

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