Read the statement by Michael Teeuw here.
MMM-MealViewer
-
Open the developers window, ctrl-shift-i on the keyboard. Select the console tab and scroll up to see any errors. Usually red text
-
@sdetweil Thank you. That’s helpful (I’m still learning the ins and outs of Magic Mirror) but there’s no errors. The “Undefined” is coming up while it’s loading the data. There’s no documentation for the module, I’m thinking there’s something that’s missing in the setup.
-
@gonzonia can u should your config info?
looking at the code, these are the options that are configurable
defaults: { schools: [], maxWidth: "300px", updateInterval: 5 * 60 * 1000, interval: 1000 * 60 * 15, }
where schools is an array of names
[ ‘school1’,school2’, ‘school3’]used to call the api
https://api.mealviewer.com/api/v4/school/’ + this.config.schools[i]
school names can be found here
https://schools.mealviewer.com/comment says only for one day
// Currently set to only pull one day’s data so endDayFormatted = todayFormatted -
@sdetweil
Thanks. I actually went in to the code and tweaked it. It was pulling the data fine, I think the issue was that the original developer’s usage only had a single meal (Lunch) available at the school and so it worked as is. Our school has Breakfast and Lunch I added an additional iteration to show all the meals or just what was placed in the config. The header now also reflects that. I’m not sure what that was supposed to do before because I couldn’t figure out where it was expecting the data.header to come from since nothing was loaded.My changes can be found here.
https://github.com/gonzonia/MMM-MealViewer/tree/patch-1
added shortName to config to replace text based on config option instead of hardcoded
changed className to menuWrapper to allow for style control without interfering with other modules
added config option for showing single or multiple meals based on name, default is AllStill need to add some documentation but it might be a couple of weeks.
-
The module works great on the initial load. The problem is that it doesn’t seem to be updating. After 12pm it’s supposed to start showing the next days meals but doesn’t. Even the next day it doesn’t update. I’ll try to dig into the core aspects of developing a module and see if I can find out why, but if anyone with more experience has any ideas where I should start looking I’d appreciate it.
-
Okay. I’ve identified the problem. In the code below, everything gets setup in the “start” function. Then it calls getMenuData. That function ends by setting up a timer to call itself but isn’t supplying the object necessary. This means it won’t work. If I add the _this object to pass it causes all sorts of problems.
I’m not a js expert. I’m sure a way to re-factor this will eventually occur to me, but right now I’m just not seeing it.start: function() { Log.log('Starting module: ' + this.name); // Set up the local values var today = moment(); this.loaded = false; this.urls = []; this.results = []; // Uses now are today if before noon and tomorrow as today if after noon if (today.hour() >= 12) { var todayFormatted = today.add(1, 'day').format('MM-DD-YYYY'); } else { var todayFormatted = today.format('MM-DD-YYYY'); } // Currently set to only pull one day's data so endDayFormatted = todayFormatted //var endDay = today.add(config.showDays, 'days'); //var endDayFormatted = endDay.format('MM-DD-YYYY'); var endDayFormatted = todayFormatted; // Construct the url array for the schools for (var i in this.config.schools) { this.urls.push({school: this.config.schools[i], url: 'https://api.mealviewer.com/api/v4/school/' + this.config.schools[i] + '/' + todayFormatted + '/' + endDayFormatted + '/'}); } // Trigger the first request this.getMenuData(this); }, getMenuData: function(_this) { // Make the initial request to the helper then set up the timer to perform the updates _this.sendSocketNotification('GET-MENU-DATA', _this.urls); setTimeout(_this.getMenuData(), _this.config.interval, _this); },
-
@gonzonia said in MMM-MealViewer:
getMenuData: function(_this) {
// Make the initial request to the helper then set up the timer to perform the updates
_this.sendSocketNotification(‘GET-MENU-DATA’, _this.urls);
setTimeout(_this.getMenuData(), _this.config.interval, _this);
},do this
getMenuData: function(_this) { // Make the initial request to the helper then set up the timer to perform the updates _this.sendSocketNotification('GET-MENU-DATA', _this.urls); setTimeout(function() {_this.getMenuData(_this)}, _this.config.interval); },
this creates a little inline function which CAN pass parms on to the next routine
-
@sdetweil Thanks! I’ll make the change and see what happens when it should update mid-day tomorrow.
-
Or you could do this:
scheduleUpdate: function() { setInterval(() => { this.getMenuData(); }, this.config.updateInterval); }, getMenuData: function() { this.sendSocketNotification('GET-MENU-DATA'); }
At the top of the main js you set the interval:
updateInterval: 15 * 60 * 1000,
Then in the start section you call it:
// Define start sequence. start: function() { Log.info("Starting module: " + this.name); this.scheduleUpdate(); },
Either the way Sam showed you or the above will work :)
-
@cowboysdude Thanks! I might switch to that. I’ve had to rework it a little because the URL wasn’t getting set except at the first call. I just moved setup for that into the getMenuData and I think it’s all working now. I’ll give it a day to run and see what happens tomorrow before I try messing with it again and update the file on github.
-updated to fix grammar