Read the statement by Michael Teeuw here.
MMM-MealViewer
-
@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
-
Sam is a REALLY smart guy so he gives you the smart guy answer…
I’m not as smart so I give you my dumb guy answer LOLIt will work either way … so now you def have an answer that works :)
-
@cowboysdude said in MMM-MealViewer:
Sam is a REALLY smart guy so he gives you the smart guy answer
nah, Sam is the LAZY guy… change as LITTLE as possible. especially for folks just starting out
-
Well, thanks to both of you! I can confirm it is finally working.
Now to update github. Someday I should write some documentation too.
-
@cowboysdude, I’m looking for the part where you “change” the XML data to JSON data. I’m trying to write a new MMM, but the data is presented in XML. I like the have it in JSON, so I can use it.
Maybe I read over it, but I cannot figure out where you do this.
-
@htilburgs there are a few xml to json modules
https://www.npmjs.com/package/xml2js
google search
‘nodejs xmltojson’here is one with a just code, no extra libs
-
@sdetweil , I’ve found them, but I don’t know how to use it in combination with the URL that creates the XML.
Indeed the last one with no extra libs looks promising. I tried to simply add this in the node_helper.js but getting stuck at how to use it.
I’ve looked into all the MMM Modules but cannot seem to find an example.