MagicMirror² v2.12.0 is available! For more information about this release, check out this topic.

SimpleLogo auto change logo not working



  • I installed SimpleLogo and have it showing my custom logo, however I can’t seem to figure out what changes need to be done to make the logo auto change.
    I did install the onscreen menu and have it working, what am I missing?
    Thank you for any advise you can give me.



  • @RoadRunnr1469 what is SimpleLogo?

    can u post that part of your config.js for this module?

    the doc says

    refreshInterval	
    
    Refresh/refetch image file between interval. Only use this if your image url return different image after some interval of time, even the fileUrl is not changed. See this case #2, awesome project by @ElYoM
    
    Possible values: 1000, 2000, or 10000
    Default value: 0 (disabled)
    


  • @sdetweil I left that as default in the MMM-SimpleLogo.js - it isn’t clear what needs to change in there.



  • Module.register("MMM-SimpleLogo", {
        // Default module config.
        defaults: {
            text: "",
            fileUrl: "modules/MMM-SimpleLogo/public/Amc.JPG",
            width: "200px",
    	notification: "SIMPLE_LOGO_UPDATE",
            position: "top_center",
            refreshInterval: 1000
        },
    
        start: function() {
            if (this.config.refreshInterval > 0) {
                var self = this;
                var imgsrc = self.config.fileUrl;
                this.interval = setInterval(function() {
                    img = document.querySelector(".simple-logo__container img[src*='" + imgsrc + "']");
                    imgsrc = self.config.fileUrl;
                    if(!imgsrc.includes("?"))
                            imgsrc += '?' + Date.now();
                    else
                            imgsrc += '&' + Date.now();
                    img.setAttribute('src', imgsrc);
                }, this.config.refreshInterval);
            }
        },
    
        getStyles: function () {
            return [
                this.file('css/mmm-simplelogo.css')
            ];
        },
    
        notificationReceived: function(notification, payload) {
            if (notification == "SIMPLE_LOGO_UPDATE") {
                // stop auto-refresh (if any)
                if (this.config.refreshInterval > 0) {
                    clearInterval(this.interval);
                }
                // update with new parameters
                for (var attr in payload) this.config[attr] = payload[attr];
                // restart auto-refresh (if any)
                this.start();
                this.updateDom();
            }
        },
    
        // Override dom generator.
        getDom: function() {
            var wrapper = document.createElement("div");
            wrapper.className = 'simple-logo__container';
            wrapper.classList.add(this.config.position);
            wrapper.style.width = this.config.width;
            var text = document.createTextNode(this.config.text);
            wrapper.appendChild(text);
            var img = document.createElement("img");
            img.setAttribute('src', this.config.fileUrl);
            wrapper.appendChild(img);
            return wrapper;
        }
    });
    


  • @RoadRunnr1469 u don’t edit the SimpleLogo.js file (in general u NEVER edit the module files unless u are making code fixes or enhancements)

    you edit the config.js

    default is NEVER update

    in config.js

     {
       module: "MMM-SimpleLogo",
       position: ????,
       config: {
          refreshInterval:  5* 60 * 1000   // 5 minutes, times  60 seconds times 1000 milliseconds per second
          fileUrl: "???????"
       } 
    }
    

    everything in the config: { … }
    overrides the moduleName.js defaults: { …} items of the same names



  • As @sdetweil stated you shouldn’t be editing the modules JavaScript file.

    To ensure that the SimpleLogo module has not been damaged I would reinstall the module and the OnScreenMenu module if you edited the JavaScript of that too.

    Once you have a fresh install of SimpleLogo and OnScreenMenu you need to edit the config file in magic mirror and not any of the module files.

    I’m not sure what you mean about the “auto chance” aspect. If you want the logos to automatically change then I would suggest sending a notification to SimpleLogo using ModuleScheduler. On the other hand, if you want to manually change them. You can use the OnScreenMenu module like so:

    {
        module: "MMM-OnScreenMenu",
        position: "top_centre",
        config: {
            menuItems: {
                notify1: {
                    title: "AMC Logo",
                    notification: "SIMPLE_LOGO_UPDATE",
                    payload: {
                        fileUrl: "modules/MMM-SimpleLogo/public/Amc.JPG",
                        width: "750px"
                    }
                },
                notify2: {
                    title: "Show other logo",
                    notification: "SIMPLE_LOGO_UPDATE",
                    payload: {
                        fileUrl: "modules/MMM-SimpleLogo/public/......",
                        width: "1050px"
                    }
                }
            }
        }
    }
    

    which should hopefully give you the option to change the logo manually.

    Hope this helps.



  • I don’t understand why people have to be so confrontational and un helpful. Making changes the the DEFAULT portion of the main file ONLY affects the initial settings.

    As far as what I mean by auto changing logo, that is what I understood by the documentation for the module.
    Dynamic to me means it will change at a given amount of time…

    ****** Copy/Paste from MMM-SimpleLogo*****
    The MMM-SimpleLogo module supports the notification event SIMPLE_LOGO_UPDATE which allows the configuration to be dynamically modified. As an example, the MMM-OnScreenMenu module might be used to dynamic adjust the fileURL parameter as follows




  • @sdetweil changing the simplelogo.js back and putting updates in config.js has not made any changes. the logo still stays on the same logo, never changes.



  • @RoadRunnr1469 ok, looking thru the code and doc

    Refresh/refetch image file between interval. Only use this if your image url return different image after some interval of time, even the fileUrl is not changed.
    

    the code adds a time to the end of the fileurl to force a unique value. You could do this if the URl to the file stayed the same, but the actual file was different (something overwrote the file since last time)

    so, they planned on the something changing the actual logo file contents

            var imgsrc = self.config.fileUrl;
                this.interval = setInterval(function() {   // < --- start a recurring timer
                    img = document.querySelector(".simple-logo__container img[src*='" + imgsrc + "']");
                    imgsrc = self.config.fileUrl;
                    if(!imgsrc.includes("?"))
                            imgsrc += '?' + Date.now();  // < ---
                    else
                            imgsrc += '&' + Date.now();  // < -----
                    img.setAttribute('src', imgsrc);
                }, this.config.refreshInterval);  // < ---  refresh time
            }
    

    the code also allows some other module to send it a message to change the logo url

    I don’t understand why people have to be so confrontational and un helpful.
    

    we are not being ‘un helpful’, the design of the mirror app is to INTENTIONALLY keep people from having to change the module file for different options…

    so, when we see someone going down that path, we want to get them back on the design
    I can look at the module code from github, I can’t see what you did locally. (in general)
    makes it harder to help, and changes made get wiped out if there is a module update…
    (that tends to make people upset when their stuff is lost!)

    but your and my initial understanding of what was supposed to happen (as I didn’t know anything about this module), is wrong… update the cycle time but keep the same exact image and nothing will change.
    you can prove this with 2 logo files.

    start with one, and then copy the other over the 1st while the module is working.

    we are all volunteers here…



  • The ReadMe file shows this
    cat README.md

    Module: MMM-SimpleLogo

    The MMM-SimpleLogo module is third party modules of the MagicMirror. This module simply displays logo.

    Using the module

    To use this module, add it to the modules array in the config/config.js file:

    modules: [
        {
            module: 'MMM-SimpleLogo',
            position: 'top_left',    // This can be any of the regions.
            config: {
                // The config property is optional.
                // See 'Configuration options' for more information.
            }
        }
    ]
    

    Configuration options

    The following properties can be configured:

    <thead>
    	<tr>
    		<th>Option</th>
    		<th>Description</th>
    	</tr>
    <thead>
    </thead></thead><tbody>
    	<tr>
    		<td><code>fileUrl</code></td>
    		<td>File url.<br />
    			<br /><b>Possible values:</b> Logo link form internet or path to your local files relative to MagicMirror directory
    			<br /><b>Default value:</b> <i>'modules/MMM-SimpleLogo/public/logo.png'</i>
    		</td>
    	</tr>
    	<tr>
    		<td><code>width</code></td>
    		<td>Set width of your logo, height is auto.<br />
    			<br /><b>Possible values:</b> <code>'300px'</code> or <code>'50%'</code>
    			<br /><b>Default value:</b> <code>'200px'</code>
    		</td>
    	</tr>
    	<tr>
    		<td><code>position</code></td>
    		<td>Horizontal position on current container<br />
    			<br /><b>Possible values:</b> <code>left</code>, <code>center</code>, or <code>right</code>
    			<br /><b>Default value:</b> <code>left</code>
    		</td>
    	</tr>
    	<tr>
    		<td><code>refreshInterval</code></td>
    		<td>Refresh/refetch image file between interval. Only use this if your image url return different image after some interval of time, even the <code>fileUrl</code> is not changed. See this case #2, awesome project by @ElYoM <br />
    			<br /><b>Possible values:</b> <code>1000</code>, <code>2000</code>, or <code>10000</code>
    			<br /><b>Default value:</b> <code>0</code> (disabled)
    		</td>
    	</tr>
    	<tr>
    		<td><code>text</code></td>
    		<td>Text above the image.<br />
    			<br /><b>Possible values:</b> Any text
    			<br /><b>Default value:</b> <code>Simple Logo</code>
    		</td>
    	</tr>
    </tbody>
    

    Notification Events

    The MMM-SimpleLogo module supports the notification event SIMPLE_LOGO_UPDATE which allows the configuration to be dynamically modified. As an example, the MMM-OnScreenMenu module might be used to dynamic adjust the fileURL parameter as follows:

    {
        module: "MMM-OnScreenMenu",
        position: "top_left",
        config: {
            menuItems: {
                notify1: {
                    title: "Show Cat",
                    notification: "SIMPLE_LOGO_UPDATE",
                    payload: {
                        fileUrl: "cat.jpg",
                        width: "750px"
                    }
                },
                notify2: {
                    title: "Show Dog",
                    notification: "SIMPLE_LOGO_UPDATE",
                    payload: {
                        fileUrl: "dog.jpg",
                        width: "1050px"
                    }
                }
            }
        }
    }

Log in to reply