MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. zichao92
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    Z
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 33
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth ,

      I managed to have some developments with your remote control module’s sendNotifcation command. I hooked up the MM using a browser and observed( using dev console, Note to beginners: press F12 on a browser to access this cool feature ) that a notification was send from MM Remote. This means that you were right all along, just that i didnt know how to observe the sendNotification command via dev console.

      Currently, i have another issue. My youtube.js module receives the “PLAY_VIDEO” or “PAUSE_VIDEO” notification but is not able to perform what was desired.

      Here’s my snippet of my code from my youtube.js :

      notificationReceived: function(notification, payload) {
      		if (notification === "PAUSE_VIDEO"){
      			pausethevideo()
      
      		}
      		if (notification === "PLAY_VIDEO"){
      			playthevideo()
      
      		}
      	},
      
      getDom: function() {
      var wrapper = document.createElement("div");
      		wrapper.className = "thin xlarge bright";
      
      		function playthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.playVideo();
      		};
      
      		function stopthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.stopVideo();
      		};
      
      		function pausethevideo(){
      		var myPlayer = document.getElementById('my-video'); 
      		myPlayer.pauseVideo();
      		};
      		
      		
      		wrapper.innerHTML='<div> <div> allowfullscreen></div></div>'; //youtube video link found here.
      
      		
      
      			return wrapper;
      	}
      
      });
      

      However, i got an error from dev console :
      Uncaught TypeError: Cannot read property 'pauseVideo' of null at Class.notificationReceived (youtube.js:69)

      Im suspecting that my pauseVideo/playVideo function wasn’t recognised as it is getDom.

      Will appreciate any help or advice !

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      Hi all, im not too sure if i have made any mistake regarding the structure of MMM.

      I placed my notificationReceived at the front end of embedded youtube, which i called it youtube.js( it doesnt have any node_helper) :

      Here’s the code of my youtube.js , the codes are heavily based on a the default module called “compliments” :

      module.register("youtube",{
      
      	// Module config defaults.
      	defaults: {
      
      		updateInterval: 30000,
      		fadeSpeed: 4000
      	},
      
      
      
      	// Define required scripts.
      	getScripts: function() {
      		return ["moment.js"];
      //		exec("sudo python /home/pi/NicoRFID/RFID_playlist.py");
      	},
      	getStyles: function() {
      	    return [
      	        'script.css', // will try to load it from the vendor folder, otherwise it will load is from the module folder.
      	    ]
      	},
      
      	// Define start sequence.
      	start: function() {
      		Log.info("Starting module: " + this.name);
      
      		
      		// Schedule update timer.
      		var self = this;
      		setInterval(function() {
      			self.updateDom(self.config.fadeSpeed);
      		}, this.config.updateInterval);
      	},
      		
      
      		
      	/* randomIndex(compliments)
      	 * Generate a random index for a list of compliments.
      	 *
      	 * argument compliments Array - Array with compliments.
      	 *
      	 * return Number - Random index.
      	 */
      
      	/* complimentArray()
      	 * Retrieve an array of compliments for the time of the day.
      	 *
      	 * return compliments Array - Array with compliments for the time of the day.
      	 */
      	
      	/* complimentArray()
      	 * Retrieve a random compliment.
      	 *
      	 * return compliment string - A compliment.
      	 */
      		notificationReceived: function(notification, payload) {
      		if (notification === "PAUSE_VIDEO"){
      			pausethevideo()
      
      		}
      		else if (notification === "PLAY_VIDEO"){
      			playthevideo()
      
      		}
      	},
      
      
      	// Override dom generator.
      	getDom: function() {
      		//var complimentText = this.randomCompliment();
      		//var complimentText = "Hi NUS GOD Puay Hiang ";
      
      		//var compliment = document.createTextNode(complimentText);
      
      		var wrapper = document.createElement("div");
      		wrapper.className = "thin xlarge bright";
      
      		function playthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.playVideo();
      		};
      
      		function stopthevideo(){
      		var myPlayer = document.getElementById('my-video');
      		myPlayer.stopVideo();
      		};
      
      		function pausethevideo(){
      		var myPlayer = document.getElementById('my-video'); 
      		myPlayer.pauseVideo();
      		};
      		
      		
      		wrapper.innerHTML='<div> <div> allowfullscreen></div></div>';
      
      		
      
      		
      
      			
      		//wrapper.appendChild(compliment);
      
      		return wrapper;
      	}
      
      });
      

      So with the notificationReceived line, i intend to control my video using the remote control with these codes :

      / edit menu buttons
              "show-all-button": function() {
              var parent = document.getElementById("visible-modules-results");
              var buttons = parent.children;
              for (var i = 0; i < buttons.length; i++) {
               if (buttons[i].id!="module_5_youtube"){
                  if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-off", "toggled-on");
                  Remote.showModule(buttons[i].id);
                  var notification = "PAUSE_VIDEO";
                  Remote.getWithStatus("action=NOTIFICATION&n"+"otification=" + notification );
                  }
              else{
                      if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-on", "toggled-off");
                  Remote.hideModule(buttons[i].id);
                              }
      

      Am i doing something wrong here?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Python Shell not working properly on MM

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

      posted in Troubleshooting
      Z
      zichao92
    • RE: Python Shell not working properly on MM

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

      posted in Troubleshooting
      Z
      zichao92
    • RE: Python Shell not working properly on MM

      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'); });

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth, I realized i was using an older version of your remote control. However, after updating the remote control module, i inserted your recommended line back into this code:

        // edit menu buttons
              "show-all-button": function() {
              var parent = document.getElementById("visible-modules-results");
              var buttons = parent.children;
              for (var i = 0; i < buttons.length; i++) {
               if (buttons[i].id!="module_5_youtube"){
                  if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-off", "toggled-on");
                  Remote.showModule(buttons[i].id);
                  var notification = "SCREEN_WAKEUP";
                  Remote.getWithStatus("action=NOTIFICATION&n"+"otification=" + notification );
                  }
              else{
                      if (Remote.hasClass(buttons[i], "external-locked")) {
                      continue;
                  }
                  buttons[i].className = buttons[i].className.replace("toggled-on", "toggled-off");
                  Remote.hideModule(buttons[i].id);
                              }
      

      I was testing this code with paviro’s PIR module ( https://github.com/paviro/MMM-PIR-Sensor) on this line which is found from his MMM-PIR-Sensor.js .

      	notificationReceived: function(notification, payload) {
      		if (notification === "SCREEN_WAKEUP"){
      			this.sendNotification(notification, payload)
      		}
      	},
      

      I modified the PIR code in such a way that when it receives the SCREEN_WAKEUP notification , it will perform certain actions for me rather than turning on the monitor.

      posted in Troubleshooting
      Z
      zichao92
    • 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?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth ,

      I tried that method to send a notification to the node_helper.js and from there, to broadcast the notification ‘PAUSE_VIDEO’ via sendNotifcation to another module with notificationReceived code at the receiving end.

      However, I got an error stating that sendNotifcation as error reported as TypeError: this.sendNotification is not a function . Is there any work around to this?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      Hi @Jopyth ,

      I looked through your code regarding generic notification request under your MMM remote. However, im not too sure how to incorporate the notification request into my modification. I tried replacing this.sendNotification("PAUSE_VIDEO", payload); with ?action=NOTIFICATION¬ification=PAUSE_VIDEO, however it doesnt work.

      Can you assists me regarding this?

      posted in Troubleshooting
      Z
      zichao92
    • RE: Controlling Embedded Youtube Video on MM

      @Jopyth , yea I’m using and modifying your remote module. Thanks for the tip, will try it out soon

      posted in Troubleshooting
      Z
      zichao92
    • 1 / 1