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