<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Building my first module, using MMM-API]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I’m trying to build my first module for MagicMirror, the plan is to build a PiggyBank.<br />
Basically this would consist on a PiggyBank image that would be visible according to the percentage of money you have related to the target e.g. if we have 30% left to the target the bottom 70% of the image will be visible and 30% of the image will be hidden.</p>
<p dir="auto">The target and the amount of money saved will be stored in a JSON file. According to what i’ve seen the code that handles the store/retrieve of data should be placed in node_helper.js.</p>
<pre><code>.
├── CHANGELOG.md
├── Gruntfile.js
├── LICENSE.txt
├── MMM-PiggyBank.css
├── MMM-PiggyBank.js
├── node_helper.js
├── package.json
├── README.md
└── translations
    ├── en.json
    └── es.json
</code></pre>
<p dir="auto">The module <strong>MMM-Api</strong> would be used to change the target or the amount of money saved.</p>
<p dir="auto">Now my question, in the <strong>MMM-Api</strong> documention the target is an ACTION in the module. My question here is where do i define the ACTION? Could you kindly show me a mockup/skeloton of and ACTION?</p>
<pre><code>MAGIG_MIRROR_IP:PORT/api/v1/modules/MODULE_NAME/ACTION?payload1key=payload1value&amp;payload2key=payload2value
</code></pre>
<p dir="auto">An ACTION is just the name of a function inside MODULE_NAME.js e.g. processData?</p>
<pre><code>processData: function(data) {
</code></pre>
<p dir="auto">Please bear in mind that I’m new to MagicMirror and to nodejs as well.<br />
I took the chance to look at <a href="https://forum.magicmirror.builders/topic/8534/head-first-developing-mm-module-for-extreme-beginners">Head first developing MM module for extreme beginners</a>  and <a href="https://github.com/MichMich/MagicMirror/blob/master/modules/README.md" target="_blank" rel="noopener noreferrer nofollow ugc">MagicMirror2 Module Development Documentation</a> but failed to understand how the ACTION should be defined.</p>
<p dir="auto">Thanks in advance,<br />
Edgar Santos</p>
]]></description><link>https://forum.magicmirror.builders/topic/8887/building-my-first-module-using-mmm-api</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 05:11:02 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/8887.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Oct 2018 16:30:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Building my first module, using MMM-API on Tue, 18 Dec 2018 11:38:36 GMT]]></title><description><![CDATA[<p dir="auto">Finally finished my first module.<br />
Nothing too fancy but fits my requirements.</p>
<p dir="auto"><a href="https://github.com/PTcrusher/MMM-PiggyBank" target="_blank" rel="noopener noreferrer nofollow ugc">GitHub Link</a></p>
]]></description><link>https://forum.magicmirror.builders/post/48272</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/48272</guid><dc:creator><![CDATA[PTcrusher]]></dc:creator><pubDate>Tue, 18 Dec 2018 11:38:36 GMT</pubDate></item><item><title><![CDATA[Reply to Building my first module, using MMM-API on Mon, 05 Nov 2018 21:08:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ptcrusher" aria-label="Profile: ptcrusher">@<bdi>ptcrusher</bdi></a><br />
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.</p>
]]></description><link>https://forum.magicmirror.builders/post/46355</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/46355</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 05 Nov 2018 21:08:04 GMT</pubDate></item><item><title><![CDATA[Reply to Building my first module, using MMM-API on Mon, 05 Nov 2018 17:32:04 GMT]]></title><description><![CDATA[<p dir="auto">@Sean Did some progress on the module. I removed the dependency on MMM-API since we can define extra routes in node_helper.js.</p>
<p dir="auto">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?</p>
<p dir="auto">Could you kindly tell me which is the recommended approach?</p>
<pre><code>extraRoutes: function() {
                var self = this;
                this.expressApp.get("/MMM-PiggyBank/WITHDRAW", function(req, res) {
                        self.withdrawCash().then((rsp) =&gt; 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) =&gt; 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);
                }
        },
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/46347</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/46347</guid><dc:creator><![CDATA[PTcrusher]]></dc:creator><pubDate>Mon, 05 Nov 2018 17:32:04 GMT</pubDate></item><item><title><![CDATA[Reply to Building my first module, using MMM-API on Tue, 09 Oct 2018 18:06:31 GMT]]></title><description><![CDATA[<p dir="auto">@sean Got it! Thanks</p>
]]></description><link>https://forum.magicmirror.builders/post/45183</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/45183</guid><dc:creator><![CDATA[PTcrusher]]></dc:creator><pubDate>Tue, 09 Oct 2018 18:06:31 GMT</pubDate></item><item><title><![CDATA[Reply to Building my first module, using MMM-API on Tue, 09 Oct 2018 17:56:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ptcrusher" aria-label="Profile: ptcrusher">@<bdi>ptcrusher</bdi></a><br />
As I read the document of <code>MMM-API</code>, <code>ACTION</code> would be the name of notification of target module. (It’s obvious whether notification could be case-insensitive.)<br />
By example,<br />
<code>MMM-Glance</code> module works with notification <code>GLANCE_ON</code>, Thus <code>MMM-API</code> doc says</p>
<pre><code>curl -X POST 'http://localhost:3001/api/v1/modules/mmm-glance/glance_on?name=news&amp;time=1000'
</code></pre>
<p dir="auto">will activate <code>MMM-Glance</code>. This <code>curl</code> execution will be equivalent with the notification <code>GLANCE_ON</code> with payload value <code>{name:"news", time:1000}</code>.</p>
]]></description><link>https://forum.magicmirror.builders/post/45182</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/45182</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 09 Oct 2018 17:56:32 GMT</pubDate></item></channel></rss>