• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

multiple module instances overwrites itself values

Scheduled Pinned Locked Moved Unsolved Development
13 Posts 7 Posters 9.0k Views 9 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    BenRoe Module Developer
    last edited by Sep 27, 2016, 9:42 PM

    Ok other question.
    If i setup a module twice in the config, do they share the variables from the code?

    1 Reply Last reply Reply Quote 0
    • D Offline
      DazDavid
      last edited by Nov 28, 2016, 12:41 PM

      Any news here?

      B 1 Reply Last reply Dec 4, 2016, 11:14 PM Reply Quote 0
      • B Offline
        BenRoe Module Developer @DazDavid
        last edited by Dec 4, 2016, 11:14 PM

        @DazDavid nope

        1 Reply Last reply Reply Quote 0
        • C Offline
          chrisyy
          last edited by Dec 5, 2016, 7:15 AM

          Would it work if u give them names like MMM-FHEM1 and MMM-FHEM2?

          Cause if u add two instances with the same name in the config i can imagine, that he will read the first value and overwrites them in the second instance. Like

          var variable = 1;
          var variable = 2;

          Output would be 2.

          1 Reply Last reply Reply Quote 0
          • B Offline
            bobbob601
            last edited by Apr 18, 2017, 3:51 PM

            most of modules don’t support multi-instance because the way magicmirror is done, they share node_helper and thus, both instances received all notifications so the last notification will overwrite both modules.

            either you duplicate the module (and edit the source code a little bit) or the module itself but be rewrittent to manage multi-instances.

            B 1 Reply Last reply Apr 18, 2017, 3:57 PM Reply Quote 3
            • B Offline
              BenRoe Module Developer @bobbob601
              last edited by Apr 18, 2017, 3:57 PM

              @bobbob601 thx for the answer. Do you have a example how to write a module with multi-instace support?

              R 1 Reply Last reply Apr 18, 2017, 4:06 PM Reply Quote 0
              • R Offline
                RedNax Module Developer @BenRoe
                last edited by RedNax Apr 18, 2017, 4:07 PM Apr 18, 2017, 4:06 PM

                @BenRoe

                Having the same problem with my module… A theoretical solution could be to make node_helper multi instance aware by appending some identifier to the notification unique to the instance: ie GET_WEATHER_001… The helper triggers on GET_WEATHER and builds an array with the different notifications and payloads. It then periodically runs through the array getting the appropriate requests and sending out notifications like WEATHER_001 with the specific payload.

                Haven’t built it yet though…

                1 Reply Last reply Reply Quote 0
                • B Offline
                  bobbob601
                  last edited by Apr 18, 2017, 7:49 PM

                  @BenRoe nope. And I tried several months ago without success. But I’m trying it now (thought I’ll not be able to test before the next week). If it works, it could be easily implemented everywhere and furthermore, I have an idea to simplify it a little bit by improving Magic Mirror itself.

                  I’ll come back here after my tests

                  T 1 Reply Last reply Apr 18, 2017, 9:44 PM Reply Quote 0
                  • T Offline
                    trgraglia @bobbob601
                    last edited by Apr 18, 2017, 9:44 PM

                    @bobbob601 I got it working by passing a unique ID to the node helper and passing it back from the node helper.

                    https://github.com/trgraglia/MMM-MVG-LocalTransport

                    Hope this helps.

                    http://www.anthonygraglia.com/

                    1 Reply Last reply Reply Quote 1
                    • B Offline
                      bobbob601
                      last edited by bobbob601 Apr 19, 2017, 12:54 PM Apr 19, 2017, 12:44 PM

                      same than mine :) coded exactly like you while I was on the plane I just pushed but not tested (sadly I pushed it on my master :-/)
                      https://github.com/lgmorand/MMM-Ratp

                      socketNotificationReceived: function(notification, payload) {
                              Log.info("Notif:" + notification);
                              if (notification === "TRANSPORTS") {
                                  if (this.config.debugging) {
                                      Log.info("Transports received");
                                      Log.info(payload.lineInfo);
                                      Log.info(payload.transports);
                                  }
                      
                                  if(this.config.uniqueID == payload.uniqueID) // just in case of multi instances
                                  {
                                      this.transports = payload.transports;
                                      this.lineInfo = payload.lineInfo;
                                      this.loaded = true;
                                      this.updateDom(this.config.animationSpeed);
                                  }
                      }
                      

                      At least, thanks to you, I know it can work :)

                      my idea to improve it was to auto-generate a ID for the module, not in the config, but generated by the Magic Mirror on loading. it should be easy to implement. Once this ID generated, it is accessible from the node_helper and the module.js. this way, no need to declare a uniqueID in the config

                      T 1 Reply Last reply Apr 19, 2017, 10:03 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      • First post
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy