Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    Need helping sending notifications between module and module node_helper

    Development
    2
    8
    983
    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
      Seann Module Developer last edited by

      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
        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)

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

            S 2 Replies Last reply Reply Quote 0
            • S
              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
                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
                  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

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    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 Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                    This forum is using NodeBB as its core | Contributors
                    Contact | Privacy Policy