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.

    Slideshow Module with PDF support

    Scheduled Pinned Locked Moved Development
    1 Posts 1 Posters 777 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.
    • F Offline
      flashnatic
      last edited by

      Hey guys,

      I need your help :).

      My module “Pictures” can show any kind of pictures, located on a mounted network drive. On startup node_helper mounts a specific drive, then it scans this folder every two seconds (it could be any other value) and write all filenames in a text file. Pictures imports and filters this file. At the end it generates a slideshow.

      Now I want to implement pdf files in the same way. Actually it works with a little workaround but I’m not happy with that. I have to start MagicMirror and additionally I have to start another browser (unfortunatelly “node serveronly” doesn’t work) on the pi to show pdf files with the integrated plugin.

      For that I have several questions^^:

      • Is there a possibility to show pdf files native in my module?
      • My slideshow is a little laggy on the pi (3B). Any PC with the same network connection shows the same slideshow in browser with perfect performance. Can I improve my slideshow performance anyhow?
      • I have a problem to run “node serveronly” with raspian stretch an the new MagicMirror 2.3.1. I can start but as soon as I connect to the pi by IP:8080 my module generates -75 errors. This won’t happen if MagicMirror runs with “npm start”.

      Best regards
      flash

      node_helper.js

      var request = require('request');
      var NodeHelper = require("node_helper");
      const exec = require('child_process').exec;
      
      module.exports = NodeHelper.create({
      
      	start: function() {
      		this.started = false;
      	},
      
      	socketNotificationReceived: function(notification, payload) {
      		if (notification === "CONFIG" && this.started == false) {	
      			this.config = payload;
      			// mounting network drive
      			exec("/usr/bin/sudo mount -t cifs -o user=" + this.config.user + ",password=" + this.config.password + " " + this.config.source + " /home/pi/MagicMirror/modules/Pictures/images", null);
      			this.started = true;
      		}		
      		if (notification === "GET_PICTURE_DATA" && this.started) {
      			var path = "/home/pi/MagicMirror/modules/Pictures/images/"+ this.config.folder + "/";
      			var opt1 = '-type f ! -path "/home/pi/MagicMirror/modules/Pictures/images/' + this.config.folder + '/.thumb/*" | awk -F"/"'
      			var opt2 = '{print $NF"/" }';
      			var opt3 = '| sort > ~/MagicMirror/modules/Pictures/files.txt';
      			
      			exec("find " + "'" + path + "' " + opt1 + " '" + opt2 + "' " + opt3, null);
      			this.getData(payload);
      		}
      	},
      
      	getData: function(options) {
      		request(options, (error, response, body) => {
      			this.sendSocketNotification("PICTURE_DATA", body); 
      		});
      	}
      });
      

      Pictures.js

      var showPicture = 0;
      var textdata = [];
      var textdataHelp = [];
      var findExt = [];
      
      Module.register("Pictures",{
          defaults: {
              loadingText: 'Lade SlideShow...',
      		pictureInterval: 20 * 1000,			
          },
      	
      	start: function() {
      		Log.info("Starting module: " + this.name);	
      		this.loaded = false;		
      		this.sendSocketNotification('CONFIG', this.config);
      		this.locationSelf = window.location.href;
      		this.file = 'modules/Pictures/files.txt';	
      		setTimeout(this.updateFiles, 2000, this);
      	},
      
      	socketNotificationReceived: function(notification, payload){
      		if(notification === 'PICTURE_DATA' && payload !== null){
      			this.loaded = false;
      			textdataHelp = payload.split("/\n");			
      			if (textdataHelp[0] !== ""){
      				textdata = []; // textdata will not be cleared, if helper has no content
      			}
      			for (i = 0; i  textdata.length - 1) {
      				showPicture = 0;	
      			}	
      			self.updateDom(1000);
      			showPicture++;
      		}
          },	
      	
          getDom: function() {
      		var wrapper = document.createElement("div");	
              var pictureInfo = document.createElement('table');
      
              if (!this.loaded) {
                  wrapper.innerHTML = this.config.loadingText;
                  return wrapper;
              }
      		var currCount = showPicture + 1;
              var tableHead = document.createElement('tr');
      		tableHead.className = 'normal small';
      		
      		var y = 0
      		findExt = textdata[showPicture].split(".");
      		for (i = 0; i  0){ 
      			//tableHead.innerHTML = '<br />' + currCount + '/' + textdata.length;
      			tableHead.innerHTML = '<br />' + currCount + '/' + textdata.length;
      
      		}else{
      			tableHead.innerHTML = '<img src="' + this.locationSelf + 'modules/Pictures/images/' + this.config.folder + '/' + textdata[showPicture] +'" alt="Vorschau" /><br />' + currCount + '/' + textdata.length;
      
      		}
      		
      		y = 0;
      		findExt = [];
      		
              pictureInfo.appendChild(tableHead);		
      		
      		wrapper.appendChild(pictureInfo);	
              return wrapper;
          },	
      	
      });
      
      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