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.

    Need helping sending notifications between module and module node_helper

    Scheduled Pinned Locked Moved Development
    8 Posts 2 Posters 2.2k Views 2 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 Offline
      sdetweil
      last edited by

      what info do you want to ‘source’ from your computer? files? ???

      so the module.js sends a socketnotification message to the helper and it means ‘get info’

      the module goes back to doing whatever it does…waiting for the helper to respond sometime later

      the helper gets the notification, and then does the work for ‘get info’
      and then uses sendsocketnotification to return the response to the module

      a good programming practice to minimize work along the steps it to hard code a sample response in the node helper and use that as the response to the module… this helps get everything working…

      then you can work on filling in the actual info… and change what the node_helper does… (change how it responds)

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Offline
        Seann Module Developer
        last edited by

        @sdetweil Basically reading a folder to return all of the files contained inside. But for testing purposes I was just printing to see if the sendSocketnotification and socketNotificationReceived were actually reaching each other through each js file. I have already created the code to get each file but I had issues sending the data through socketNotifications, hence the small files I had created and sourced here to show what I had attempted.

        All I actually need is for someone to assist me by pointing me in the right direction to prove that the notifications are being sent and received correctly.
        Thanks for your reply.

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @Seann
          last edited by

          @seann node_helper.js uses console.log, and the output shows in the console window where you did npm start dev

          the module.js uses Log.log() and the output shows up in the console tab of the developers window started with npm start dev or ctrl-shift-i (letter i)

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          S 2 Replies Last reply Reply Quote 0
          • S Offline
            Seann Module Developer @sdetweil
            last edited by Seann

            @sdetweil Yeah I know that, but none of which are printing anything from the scripts posted above.
            I did try node_helper with console.log but no output so I switched to Log.info to test that too.

            1 Reply Last reply Reply Quote 0
            • S Offline
              Seann Module Developer @sdetweil
              last edited by

              @sdetweil Nevermind, received the notification now somehow. Thank you for your help.

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                sdetweil @Seann
                last edited by

                @seann and u really should wait til you get the “ALL_MODULES_STARTED” notification before starting communications between components… .like this

                //  helper.js
                var helper;
                Module.register("helper", {
                  defaults: {
                 
                  },
                  start: function(){
                    helper = this;
                    Log.info("Started Module: " + helper.name);   
                  },
                  notificationReceived: function (notification, payload) {
                           if(notification ==="ALL_MODULES_STARTED")
                		 helper.sendSocketNotification('helper_notification', {});
                	},
                  socketNotificationReceived: function(notification, payload){
                    Log.info("Helper Recieved notification: " + notification);
                  }
                });
                

                also, if you use Log.error() in the module,the messages will be easier to find in early development

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  Seann Module Developer @sdetweil
                  last edited by

                  @sdetweil Perfect, thank you! :)

                  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