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

Problem with sending socket notification to module



  • (sorry if this is a re-post, I made a post but couldn’t find it later. Admin can remove this post if needed)

    Hello,
    I’m new to MagicMirror, but I have a problem with two swedish modules:
    MMM-SL-PublicTransport
    MMM-Weather-SMHI-Hourly

    When I’m using them I get the same problem:
    Notifications from module to helper works fine
    Notifications from helper to module does not work (notifications never received).

    I don’t know how to handle this problem. I’ve spent a day with debug logs now, but I’m nowhere close to a solution.

    I would be so happy if someone with knowledge about the communication procedures could look into these two modules and see if they perhaps haven’t been updated after a “core-functionality” change.

    Thanks,
    Per Badlund, Sweden



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



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



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



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



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

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



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



  • @PerBa any update?


Log in to reply