UNSOLVED Python Shell not working properly on MM
-
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?
-
-
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'); });
-
@zichao92 Looks fine, not sure why it doesn’t work. You do not start he module multiple times, do you?
-
@Jopyth , im not too sure if i accidentally did it , is there any way to check it?
-
@zichao92 It usually should not start multiple helpers. You could insert a
console.log("Script started!");
before thePythonShell.run(...)
and see if it appears multiple times in the log? -
@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. )