Read the statement by Michael Teeuw here.
Duplicate Results Displayed With 2 Instances of MMM-pihole-stats in Config File
-
I opened this issue MMM-pihole-stats: “Duplicate Results Displayed With 2 Instances of MMM-pihole-stats in Config File”. It is issue #54.
In summary, I have two instances of MMM-pihole-stats defined in the configuration file. The first instance displays the data for pihole1 and the second instance display the data for pihole1 instead of pihole2.
The text of the issue is:
I have two Pi-Hole systems, pihole1.lan at 192.168.1.3 and pihole2.lan at 192.168.1.4. Using dig verifies the Pi-Hole names and IPs match up.
In the MM config file, the two MMM-pihole-stats modules are configured the same except for these statements:
- The position: statements, the first is top_left and the second is top_right. The instances display in the proper position.
- The header: statements, the first contains “Pi-Hole1 Statistics” and the second contains “Pi-Hole2 Statistics”. The instances display the proper header.
- The apiURL: statements, the first contains “http://pihole1.lan/api” and the second contains “http://pihole2.lan/api”. The first instance displays data for pihole1 and the second also displays data for pihole1.
Why is the second instance data not displayed? Is this module design problem or must I do something special to have multiple instances of the same module?
Butch
-
@butchkemper this module doesn’t provide support for multiple instances.
The system design of the node_helper sends a broadcast to ALL instances at once on every message sent.
The message needs to have some identifier the instance can check to see if the message is intended for it or not.
The current code does not provide that info
-
@sdetweil Sam, Thank you for the help with the answer I needed.
I am interested in learning more about MM. I have tried reading the code but have not been successful.
Do you have a recommendation about where to start for more understanding?
Butch
-
@butchkemper do you mean modules? or the base/core?
I’m not aware of anything that describes it if you don’t know how a browser works, or what a web page looks like in HTML.
-
@sdetweil I am interested in how the modules work.
I understand how a browser works and how to construct a webpage.
Butch
-
@butchkemper ok, the module development doc is here
https://docs.magicmirror.builders/module-development/introduction.html
the doc says module, but I call the JS in the browser modulename,js
cause the NAME MUST match the ‘module name’ as used in config.js module:the note I made above comes from this comment in the modules dev doc
Note 1: When a node helper sends a notification, all modules of that module type receive the same notifications.socketNotifications are ONLY between modulename.js and the node_helper.js in this module package. and the functions use the same name on both sides
sendSocketNotfication and socketNotificationReceiveda typical way to deal with this is for the modulename.js to provide the this.identifier value as part of every request to the node_helper (sendSocketNotification), and for the node_helper to send that value back on each response, (sendSocketNotification)
and THEN the modulename.js checks to see if the response value matches its this.identifier… (in the socketNotificationReceived function) if NOT then the response is for some other instance
these 3 steps are missing from the pihole-stats module componentsif you look at my sample module while reading the doc, you can see each piece
https://github.com/sdetweil/SampleModule (it does NOT use the this.identifier)and there is a little flow info missing
the node_helper.js in a module folder gets loaded at server side startup
then the MagicMirror index.html gets loaded in the browser
MagicMirror reads the config.js and loads each modules modulename.js into the browser as a script element, then calls the loaded/init/getScripts/getTemplates/getTranslations/start methods, and then finally the getDom or getTemplateData functions…
once the content is loaded into the browser DOM, then a notification is sent
MODULE_DOM_CREATED
that means code could query and manipulate content with dom methodslater when the modulename.js determines that NEW content should be displayed, it calls this.updateDom() and then MagicMirror will call back at getDom or getTemplate data, and after updating the internal DOM , it will signal via the MODULE_DOM_UPDATED notification
modules should be good citizens, and stop updating after suspend() and resume updating after resume()
if you open the browsr developers window, ctrl-shift-i, and select the elements tab, you can see the html structure of index.html filled out with the module info.
scripts added to the head block and content added to the body block
and if you use something like the MMM-pages module, you can watch the css effects as content is hidden and shownand you can use the elements tab to discover and experiment with different css styles on seleted elements to help create custom.css entries…
see the second link in my signature below for a post on that info
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login