Read the statement by Michael Teeuw here.
remoteFile in compliments module
-
@DvdEnde Please don’t get me wrong, but this is basic javascript.
this.config.remoteFile != null
checks if the variable “remoteFile” is set in your config file. Afterwards you only have two scenarios:- the variable is not set -> this if clause fails and no remote file is loaded.
- the variable is set to any value -> this if clause is true and the function complimentFile() is called, which tries to load the file defined in your config file, in my case “compliments.json”.
If loading the remote file fails you see an error message in console output of your browser. Otherwise it does not produce any log.
-
@yawns
Don’t worry, i know it is basic javascript.
@strawberry-3-141
i thought so too, but it is NOTI just now changed the compliment.js (and deleted the remoteFile completly from here) and added this within the config.
My object is simple
fadeSpeed: 4000 updateInterval: 30000
On line 33 console.log(this.config.remoteFile) = undefined
-
@yawns OK I created a compliments_test.json file and pasted your example into it and it worked. It looks like it just doesn’t work with the currentweather objects in my compliments.json file for some reason. Do I need to nest the currentweather objects within the morning, afternoon, and evening arrays perhaps?
-
@jcorraliza post your config.js and your remotefile pls
-
@schlachtkreuzer6 said in remoteFile in compliments module:
@jcorraliza post your config.js and your remotefile pls
Hi there, I posted them a few posts up. It works with the time of day objects, but not with the currentweather objects in my .json file. I’m using v2.1.0, dev branch, and I’m using the currentweather default module.
-
@DvdEnde MM is up to date and every module i git pull the latest version, nope it says it´s a invalid .json in the MM-Admin-Interface. i just can not use this config @yawns post:
{ module: 'compliments', position: 'lower_third', config: { remoteFile: 'compliments.json' } },
if i try to start MM, it´s showing up, that the config is broken. even when i adjust it to the MM-Admin code:
{ "module": "compliments", "position": "lower_third", "config": { "remoteFile": "compliments.json" } },
I´m not in javascript or anything coding. But nothing worked for me. maybe my system is somehow broken…
-
@schlachtkreuzer6
The way you do it is the way it should be.
BUT i also cannot get it to work like this.please try following:
Open config/config.js and remove"config": { "remoteFile": "compliments.json" }
Then open your compliments.js and check:
defaults: { updateInterval: 30000, remoteFile: null, fadeSpeed: 4000 },
change remoteFile to a useable name:
defaults: { updateInterval: 30000, remoteFile: "~/path to your/compliments.json", fadeSpeed: 4000 },
then restart MM (or restart the PI)
-
@DvdEnde i think my mirror has it´s own brain ^^ so i changed it like your post above. but MM just showing the default compliments. I don´t know whats wrong, but i think i will rebuild MM from the ground.
-
#@schlachtkreuzer6
If MM is showing the default compliments, where are they?
Please post the complete defaults from your compliments.js AND
the complete part of the json for compliments from your config.js.also post your jsonfile where to get your custom compliments.
maybe we all misunderstand you?
-
@DvdEnde the default compliments are in the module itself ok, here we go:
~/MagicMirror/config/config.js/* Magic Mirror Config Sample * * By Michael Teeuw http://michaelteeuw.nl * MIT Licensed. */ var config = { "port": 8080, "language": "de", "timeFormat": 24, "units": "metric", "modules": [ { "module": "alert" }, { "module": "clock", "position": "top_left" }, { "module": "calendar", "header": "Google Kalender", "position": "top_left", "config": { "calendars": [ { "symbol": "calendar", "url": "my link 1" }, { "symbol": "calendar", "url": "my link 2" }, { "symbol": "calendar", "url": "my link 3" }, { "symbol": "calendar", "url": "my link 4" }, { "symbol": "calendar", "url": "my link 4" }, { "symbol": "calendar", "url": "my link 5" } ], "timeFormat": "absolute", "maximumEntries": "20", "fadePoint": "0.55" } }, { "module": "compliments", "position": "lower_third", "config": { "compliments": { morning: [ 'Guten Morgen!', 'Wie hast du geschlafen?', 'Ich wünsche dir einen schönen Tag!' ], afternoon: [ 'Guten Tag!', 'Du schaust gut aus!', 'Wie war dein Tag!' ], evening: [ 'Guten Abend!', 'Na wie war dein Tag?', 'Du warst heute fleßig!' ], "remoteFile": "compliments.json" }, "updateInterval": 15000 } }, { "module": "currentweather", "position": "top_right", "config": { "location": "my location", "locationID": "", "appid": "my api" } }, { "module": "weatherforecast", "header": "Wetter in den kommenden Tagen", "position": "top_right", "config": { "location": "my location", "locationID": "", "appid": "my api" } }, { "module": "newsfeed", "position": "bottom_bar", "config": { "feeds": [ { "title": "Die Presse", "url": "http://diepresse.com/rss/home" } ], "showSourceTitle": true, "showPublishDate": true } }, { "module": "MMM-Remote-Control" }, { "module": "mmm-wu-moonphase", "header": "Aktuelle Mondphase", "position": "top_right", "config": { "apikey": "my api", "country": "Austria", "city": "Vienna", "apiLang": "DL" } }, { "module": "MMM-WienerLinien", "position": "top_right", "config": { "api_key": "my api", "stations": [ "abcd", "abcd" ] } }, { "module": "MMM-SpotifyConnectUI", "position": "fullscreen_below", "config": {} }, { "module": "MMM-Globe", "config": { "style": "europeDiscNat", "imageSize": 250, "ownImagePath": "", "updateInterval": 600000 } }, { "module": "internet-monitor", "position": "top_bar", "config": { "type": "minimal", "maxTime": 20000, "updateInterval": 0, "verbose": false, "displayStrength": true, "displaySpeed": false, "strengthIconSize": 40, "maxGaugeScale": 100 } }, { "module": "MMM-Traffic", "position": "top_right", "config": { "api_key": "my api", "mode": "driving", "origin": "my home", "destination": "my work", "arrival_time": "", "route_name": "Home-work", "changeColor": true, "showGreen": false, "limitYellow": 5, "limitRed": 20, "traffic_model": "pessimistic", "interval": 120000, "language": "de", "prependText": "Derzeit" }, "classes": "dimmed medium" }, { "module": "MMM-RandomPhoto", "position": "fullscreen_below", "config": { "opacity": 0.3, "animationSpeed": 1500, "updateInterval": 15, "url": "https://unsplash.it/1080/1920/?random" } }, { "module": "MMM-SystemStats", "position": "bottom_right", "config": { "updateInterval": 10000, "animationSpeed": 0 }, "classes": "small dimmed" }, { "module": "MMM-Admin-Interface" } ], "ipWhitelist": [ "::fff:0.0.0.0/1", "::fff:128.0.0.0/2", "::fff:192.0.0.0/3", "::fff:224.0.0.0/4", "127.0.0.1", "::ffff:127.0.0.1", "::1" ] }; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== 'undefined') {module.exports = config;}
this config is working perfect.
~/MagicMirror/modules/default/compliments/compliments.json (remoteFile) tried it also here ~/MagicMirror/config/compliments.json with and without absolut path.
{ "morning": [ "Test1!", "Test2?", "Test3!" ], "afternoon": [ "Test4!", "Test5!", "Test6!" ], "evening": [ "Test7!", "Test8?", "Test9!" ] }
and ~/MagicMirror/modules/default/compliments/compliments.js
* global Log, Module, moment */ /* Magic Mirror * Module: Compliments * * By Michael Teeuw http://michaelteeuw.nl * MIT Licensed. */ Module.register("compliments",{ // Module config defaults. defaults: { compliments: { morning: [ "Good morning, handsome!", "Enjoy your day!", "How was your sleep?" ], afternoon: [ "Hello, beauty!", "You look sexy!", "Looking good today!" ], evening: [ "Wow, you look hot!", "You look nice!", "Hi, sexy!" ] }, updateInterval: 30000, remoteFile: null, fadeSpeed: 4000 }, // Set currentweather from module currentWeatherType: "", // Define required scripts. getScripts: function() { return ["moment.js"]; }, // Define start sequence. start: function() { Log.info("Starting module: " + this.name); this.lastComplimentIndex = -1; if (this.config.remoteFile != null) { this.complimentFile((response) => { this.config.compliments = JSON.parse(response); }); } // 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<String> - Array with compliments. * * return Number - Random index. */ randomIndex: function(compliments) { if (compliments.length === 1) { return 0; } var generate = function() { return Math.floor(Math.random() * compliments.length); }; var complimentIndex = generate(); while (complimentIndex === this.lastComplimentIndex) { complimentIndex = generate(); } this.lastComplimentIndex = complimentIndex; return complimentIndex; }, /* complimentArray() * Retrieve an array of compliments for the time of the day. * * return compliments Array<String> - Array with compliments for the time of the day. */ complimentArray: function() { var hour = moment().hour(); var compliments = null; if (hour >= 3 && hour < 12) { compliments = this.config.compliments.morning; } else if (hour >= 12 && hour < 17) { compliments = this.config.compliments.afternoon; } else { compliments = this.config.compliments.evening; } if ( this.currentWeatherType in this.config.compliments) { compliments.push.apply(compliments, this.config.compliments[this.currentWeatherType]); } return compliments; }, /* complimentFile(callback) * Retrieve a file from the local filesystem */ complimentFile: function(callback) { var xobj = new XMLHttpRequest(); xobj.overrideMimeType("application/json"); xobj.open("GET", this.file(this.config.remoteFile), true); xobj.onreadystatechange = function () { if (xobj.readyState == 4 && xobj.status == "200") { callback(xobj.responseText); } }; xobj.send(null); }, /* complimentArray() * Retrieve a random compliment. * * return compliment string - A compliment. */ randomCompliment: function() { var compliments = this.complimentArray(); var index = this.randomIndex(compliments); return compliments[index]; }, // Override dom generator. getDom: function() { var complimentText = this.randomCompliment(); var compliment = document.createTextNode(complimentText); var wrapper = document.createElement("div"); wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright"; wrapper.appendChild(compliment); return wrapper; }, // From data currentweather set weather type setCurrentWeatherType: function(data) { var weatherIconTable = { "01d": "day_sunny", "02d": "day_cloudy", "03d": "cloudy", "04d": "cloudy_windy", "09d": "showers", "10d": "rain", "11d": "thunderstorm", "13d": "snow", "50d": "fog", "01n": "night_clear", "02n": "night_cloudy", "03n": "night_cloudy", "04n": "night_cloudy", "09n": "night_showers", "10n": "night_rain", "11n": "night_thunderstorm", "13n": "night_snow", "50n": "night_alt_cloudy_windy" }; this.currentWeatherType = weatherIconTable[data.weather[0].icon]; }, // Override notification handler. notificationReceived: function(notification, payload, sender) { if (notification == "CURRENTWEATHER_DATA") { this.setCurrentWeatherType(payload.data); } }, });
even when i change it like you said above:
defaults: { updateInterval: 30000, remoteFile: "~/MagicMirror/modules/default/compliments/compliments.json", fadeSpeed: 4000 },
It´s showing then the default compliments. (hi sexy etc.)
it´s working with my custom compliments in the config.js perfectly. but when i try this code:
{ "module": "compliments", "position": "lower_third", "config": { "remoteFile": "compliments.json" } },
MM showing the error srceen that i had to set up a config file.