Read the statement by Michael Teeuw here.
Building my first module, using MMM-API
-
@ptcrusher
As I read the document ofMMM-API
,ACTION
would be the name of notification of target module. (It’s obvious whether notification could be case-insensitive.)
By example,
MMM-Glance
module works with notificationGLANCE_ON
, ThusMMM-API
doc sayscurl -X POST 'http://localhost:3001/api/v1/modules/mmm-glance/glance_on?name=news&time=1000'
will activate
MMM-Glance
. Thiscurl
execution will be equivalent with the notificationGLANCE_ON
with payload value{name:"news", time:1000}
. -
@sean Got it! Thanks
-
@Sean Did some progress on the module. I removed the dependency on MMM-API since we can define extra routes in node_helper.js.
Now i have a doubt. Should i keep the values that i wish to retrieve in a variable and use the socketNotificationSend/socketNotificationReceived logic or… should i call the extra-routes from my module (MMM-PiggyBank.js) pretending that i’m accessing an external API?
Could you kindly tell me which is the recommended approach?
extraRoutes: function() { var self = this; this.expressApp.get("/MMM-PiggyBank/WITHDRAW", function(req, res) { self.withdrawCash().then((rsp) => res.status(rsp.status).send(rsp.response)); }); this.expressApp.post("/MMM-PiggyBank/CASH_IN", function(req, res) { self.updateCash(req.query.target,req.query.current).then((rsp) => res.status(rsp.status).send(rsp.response)); }); }, updateCash: async function(target,current) { var self = this; try { await self.checkExistance(self.fullyQualFileName()); var oldcontent = await readFile(self.fullyQualFileName()); var contentcandidate = await self.valChanges(target, current, JSON.parse(oldcontent)); var newcontent = await writeFile(self.fullyQualFileName(), JSON.stringify(contentcandidate)); return self.buildSuccessRsp("Successfully saved!"); } catch(err) { return self.buildErrRsp(err); } }, withdrawCash: async function() { var self = this; try { await self.checkExistance(self.fullyQualFileName()); var oldcontent = await readFile(self.fullyQualFileName()); return self.buildSuccessRsp(JSON.parse(oldcontent)); } catch(err) { return self.buildErrRsp(err); } },
-
@ptcrusher
I think, there might be no silver bullet or Deus Ex Machina about that kinds of question. I believe anything be good if you can handle it. -
Finally finished my first module.
Nothing too fancy but fits my requirements.