• 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.

Need helping sending notifications between module and module node_helper

Scheduled Pinned Locked Moved Development
8 Posts 2 Posters 1.9k 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
    Seann Module Developer
    last edited by Feb 9, 2019, 3:16 PM

    Basically i’m trying to source information from my computer via the node_helper.js and pass it through to my module.js
    I have looked through other modules to see how it’s done and I have taken the information I think is required.

    my node_helper.js: https://pastebin.com/r3zddnst
    my helper.js (just a development test name): https://pastebin.com/GgME83RB

    Any and all help is appreciated, thanks for reading.

    1 Reply Last reply Reply Quote 0
    • S Away
      sdetweil
      last edited by Feb 9, 2019, 3:22 PM

      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 Feb 9, 2019, 3:27 PM

        @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 Feb 9, 2019, 3:34 PM Reply Quote 0
        • S Away
          sdetweil @Seann
          last edited by Feb 9, 2019, 3:34 PM

          @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 Feb 9, 2019, 3:35 PM Reply Quote 0
          • S Offline
            Seann Module Developer @sdetweil
            last edited by Seann Feb 9, 2019, 3:37 PM Feb 9, 2019, 3:35 PM

            @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 Feb 9, 2019, 3:37 PM

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

              S 1 Reply Last reply Feb 9, 2019, 3:48 PM Reply Quote 0
              • S Away
                sdetweil @Seann
                last edited by Feb 9, 2019, 3:48 PM

                @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 Feb 9, 2019, 8:47 PM Reply Quote 0
                • S Offline
                  Seann Module Developer @sdetweil
                  last edited by Feb 9, 2019, 8:47 PM

                  @sdetweil Perfect, thank you! :)

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