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.

    Python Shell not working properly on MM

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    7 Posts 2 Posters 3.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.
    • Z Offline
      zichao92
      last edited by

      Hi guys,

      Im not too sure if anybody has this issue with the library var PythonShell = require('python-shell');.

      I wrote a python script that runs a RFID hardware that allows card tapping. Once someone taps the card, a music will play. The script works great on it’s on by using sudo python myscript.py and it’s meant to be passive, meaning that the script will keep running once it’s activated. The music will only play once once it detects the first card and it will not replay it again. However, the problem comes in when I tried to run it via PythonShell on MagicMirror.

      I realized that the script got recalled multiple times while magicmirror is running. I realized this problem when i tap the card again. This results in me hearing echo music.

      Has anyone encountered this issue before?

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        Jopyth Moderator @zichao92
        last edited by

        @zichao92 The FRITZ-Box Callmonitor module uses PythonShell, e.g. here.

        What is the specific problem you are encountering? How do you start the script? It sounds like you simply need to make sure it is only started once, and then it should work? Can you show us the code responsible for it?

        Helpful sticky: How to troubleshoot

        Z 1 Reply Last reply Reply Quote 0
        • Z Offline
          zichao92 @Jopyth
          last edited by

          Hi again @Jopyth !
          I hope im not give you a technical nightmare. Here’s the code that i was running on my MM.

          const NodeHelper = require('node_helper');
          const Gpio = require('onoff').Gpio;
          const exec = require('child_process').exec;
          var csv = require('csv-parser');
          var fs = require('fs');
          var PythonShell = require('python-shell');
          var people; 
          
          module.exports = NodeHelper.create({
            start: function () {
              this.started = false;
              this.toggleOn = false;
              
          //exec("sudo python /home/pi/NicoRFID/RFID_playlist.py"); // RFID, hk forced it here.
          
           PythonShell.run('../../../../../home/pi/NicoRFID/RFID_playlist.py', function (err) {
            if (err) throw err;
            console.log('finished');
          }); 
          
          function chaofunction(){
          fs.createReadStream('/home/pi/MagicMirror/rfid_log.csv')
            .pipe(csv())
            .on('data', function (data) {
              console.log('People Left: %s ', data.People_left);
              people = data.People_left;
            });
          }
          
          setInterval(chaofunction,4000);
          

          Notice PythonShell.run('../../../../../home/pi/NicoRFID/RFID_playlist.py', function (err) { if (err) throw err; console.log('finished'); });

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            Jopyth Moderator @zichao92
            last edited by

            @zichao92 Looks fine, not sure why it doesn’t work. You do not start he module multiple times, do you?

            Helpful sticky: How to troubleshoot

            Z 1 Reply Last reply Reply Quote 0
            • Z Offline
              zichao92 @Jopyth
              last edited by

              @Jopyth , im not too sure if i accidentally did it , is there any way to check it?

              J 1 Reply Last reply Reply Quote 0
              • J Offline
                Jopyth Moderator @zichao92
                last edited by Jopyth

                @zichao92 It usually should not start multiple helpers. You could insert a console.log("Script started!"); before the PythonShell.run(...) and see if it appears multiple times in the log?

                Helpful sticky: How to troubleshoot

                Z 1 Reply Last reply Reply Quote 0
                • Z Offline
                  zichao92 @Jopyth
                  last edited by

                  @Jopyth , the console.log didnt even appear once although the RFID is working. Another issue is that the python script will suddenly stop functioning for no reason and it will start functioning again about 1 minute later ( i realized this when the RFID didnt have any response after i tapped a card. )

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