MagicMirror² v2.7.0 is available! For more information about this release, check out this topic.

Need helping sending notifications between module and module node_helper


  • Module Developer

    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.



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


  • Module Developer

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



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


  • Module Developer

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


  • Module Developer

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



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


  • Module Developer

    @sdetweil Perfect, thank you! 🙂