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.

    Problem with sending socket notification to module

    Scheduled Pinned Locked Moved Unsolved Troubleshooting
    8 Posts 3 Posters 1.9k Views 3 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.
    • S Do not disturb
      sdetweil @PerBa
      last edited by

      @PerBa can u show your code in node helper to send?

      Usually the problem is that the ‘this’ pointer is inside some API callback, and not pointing to the node_helper instance.

      ‘this’ is always troublesome.

      That is why many module save ‘this’ at start time in ‘self’ and use ‘self’ instead of ‘this’

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • P Offline
        PerBa
        last edited by

        Re: Problem with sending socket notification to module

        The line of code that sends the notification is:

        getDepartures: function () {
        var self = this;
        ...
        self.sendSocketNotification('DEPARTURES', CurrentDeparturesArray); 
        

        the corresponding code in the module is:

        socketNotificationReceived: function (notification, payload) {
        	Log.info('MODULE:: received notification');
        	Log.info("Received Notification" + notification);
                if (notification === 'DEPARTURES') {
        

        Thanks!

        S 1 Reply Last reply Reply Quote 0
        • S Do not disturb
          sdetweil @PerBa
          last edited by sdetweil

          @PerBa

          getDepartures: function () {
          var self = this;
          

          Careful. getDepartures is not called by mm, so it’s very likely that ‘this’ is NOT pointing to the node_module instance.

          Save ‘this’ when u get the 1st socketnotification only. Just once.

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • P Offline
            PerBa
            last edited by

            Thanks for the help!
            I don’t know what happend, but I forgot to turn off the Pi during the night. This morning the Pi had crashed. I did a power-toggle and now one of the modules (the one I cleaned up regarding the “this-self”) is working.

            I must look more into this.

            Update: I now know what is behind the problem!!!
            After a power toggle everything works OK. But when I stop and restart the MagicMirror using

            pm2 stop mm
            

            and

            pm2 start mm
            

            The modules stop working.

            Does anybody know a better way of restarting the Magic Mirror?
            I must be able to do that in order to test the changes I do to the configuration…

            S D 3 Replies Last reply Reply Quote 0
            • S Do not disturb
              sdetweil @PerBa
              last edited by sdetweil

              @PerBa I do this start/stop a hundred times a day without problem.

              I kill all the node processes
              I don’t use pm2

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • D Offline
                dazza120 @PerBa
                last edited by

                @PerBa is this a Pi4 or Buster? Seems to be loads of issues with one of these. @sdetweil is the man to help though

                1 Reply Last reply Reply Quote 0
                • S Do not disturb
                  sdetweil @PerBa
                  last edited by

                  @PerBa any update?

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • 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