Need help understanding "sendNotification"



  • I’m in need of help understanding how this “sendNotification” items works from one module to the other.
    Does a module sends it in general or is it targeting a specific other module?
    And if it is sending the notification in general to all modules how must I configure the module that actualy needs to do something with those notifications?

    I would like to use MMM-Swipe (That uses 2 HC-SR04 units) to controle MMM-Pages and MMM-Page-Indicator.
    I have the Pages modules already installed. And I’m creating a test setup with the 2 ultra sonic sensors this weekend to test the workings.
    But I have no clue what file I need to alter so that when I “swipe” across the 2 sensors the pages actualy change.

    Looking at the readme-file that came with the Swipe module it says:

    This module will use the sendNotification(notification, payload) to send:
    notification = 'MOVEMENT'
    payload = 'Swipe Left', 'Swipe Right', or 'Press'
    Please use as appropriate in your module using notificationReceived(notification, payload, sender)

    While in the Pages.js file I read that that module listens to the notifications:

    Handles incoming notifications. Responds to the following:
    ‘PAGE_CHANGED’ - Set the page to the specified payload page.
    ‘PAGE_INCREMENT’ - Move to the next page.
    ‘PAGE_DECREMENT’ - Move to the previous page.
    ‘DOM_OBJECTS_CREATED’ - Starts the module.
    ‘QUERY_PAGE_NUMBER’ - Requests the current page number

    I was hoping to find something that looks like:
    if payload = then do this…

    Is there someone willing to have a look and tell me what to configure?
    I could look all day at the code and still don’t get it.



  • sendNotification is a broadcast. every other module gets it…

    they get

    the sender, the identifier, and the payload.

    the receiver must decide what to do with the information, if anything



  • @sdetweil so.
    MMM-Swipe says

     'Swipe_left'
    

    but MMM-Pages is listening for

    'PAGE_CHANGED' - Set the page to the specified payload page.
    'PAGE_INCREMENT' - Move to the next page.
    'PAGE_DECREMENT' - Move to the previous page.
    

    so, some other module needs to translate. I don’t know of a module that would do this…
    receiveNotiication Swipe_Left, and then sendNotification PAGE_DECREMENT (after checking to see if above page 0 I would assume).


  • Module Developer

    @sdetweil said in Need help understanding “sendNotification”:

    so, some other module needs to translate. I don’t know of a module that would do this…

    MMM-NotificationTrigger can do that notification translation between modules.

    receiveNotiication Swipe_Left, and then sendNotification PAGE_DECREMENT (after checking to see if above page 0 I would assume).

    {
      module: "MMM-NotificationTrigger",
      config: {
        triggers:[
          {
            trigger: "Swipe_Left",
            fires: [
              {
                 fire: "PAGE_DECREMENT"
              }
            ]
          }
        ]
      }
    }
    


  • @sean thanks for that !.. great info… amazing the contribution around this platform…



  • @sdetweil @Sean THANK YOU SOOOOOO MUCH!!!
    I’ll get right on it. Just finished my sensor setup with some small pieces of plywood. Now to fire up my pi 3A with the Pi touchscreen…install that notification trigger module and start testing!

    I do however have a question about the modules listening to the “payload”.
    Isn’t it better to have a “translator” build in a module when it can recieve notifications? Or to use a standard string (string01, string02, etc,) it listens to unless the user defines otherwise in the config.js file?


  • Module Developer

    @mwel1977
    NotificationTrigger also has payload translator, sender filter, etc.



  • @sean Thanks! 😄
    I’m just about ready setting the config for the Swipe module.
    Then is’t the Notifications turn to be configured.



  • Hmmmmmm… Hooked up the wires to the GPIO pins.
    configured the Swipe module and hit start to run the MM2.
    I know … I forgot to configure the Notification module. But I first wanted to see if the sensors worked by displaying the measured distances on the MM2 screen.

    BUT…on starting the MM2 it freezes! Ctrl+Q, Alt, Esc … nothing works.
    Only pulling the powercord out of the wallsocket! 😢 😢