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

How to receive push notifications from another server?

Scheduled Pinned Locked Moved Development
6 Posts 3 Posters 4.7k Views 3 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.
  • P Offline
    paphko
    last edited by Sep 1, 2016, 6:17 PM

    I would like to receive notifications from another server in my module. To be more precise, I have a running openhab server and I would like to display the state of lights and window contacts on my mirror. Up to now, I am using the first version of the mirror:

    magic mirror with floor plan and window contacts

    Currently, I use the openhab REST API to pull the states every 10 seconds, but this produces a lot of requests on the openhab server and an update delay of up to 10 seconds. Instead, I would like the openhab server to tell my mirror each state change. On the openhab side, I can easily add some arbitrary java code, for example to perform some http requests or to open and communicate via a socket connection to a specific IP.

    But how to implement a listener in a MM module? I don’t have much experience with electron and the new MM application infrastructure yet. How can I configure my module to receive notifications from another server? Is there maybe some module that does something similar?

    S 1 Reply Last reply Sep 1, 2016, 8:26 PM Reply Quote 0
    • M Offline
      MichMich Admin
      last edited by Sep 1, 2016, 6:20 PM

      The MagicMirror contains a SocketIO server. You could connect to that server and push notifications on the module specific channel. It’s an undocumented feature, so you might need to digg into the code.

      1 Reply Last reply Reply Quote 0
      • P Offline
        paphko
        last edited by Sep 1, 2016, 6:21 PM

        Thanks for the really quick answer! :-)
        Do you have any hint in which files I could start digging?

        1 Reply Last reply Reply Quote 0
        • P Offline
          paphko
          last edited by paphko Sep 1, 2016, 8:24 PM Sep 1, 2016, 8:22 PM

          I did some experiments but no success yet. Maybe you could clarify some things:

          • What do you mean by ‘module specific channel’? How does that work?
          • I tried to emit an event via a java application, but I don’t know which parameters to use so that the event is passed to my module?
          • Where is the code that processes incoming socket events?

          I tried socket.io-java-client, but nothing happens on the server (log remains empty, module does not return anything):

          public static void main(String[] args) throws Exception {
          	Socket socket = IO.socket("http://raspi:8080"); // I also tried: http://raspi:8080/socket-test-module
          	socket.connect();
          	socket.emit("notification", "ping");
          	socket.close();
          }
          

          Any ideas how to get a simple external socket client running?

          1 Reply Last reply Reply Quote 0
          • S Offline
            strawberry 3.141 Project Sponsor Module Developer @paphko
            last edited by Sep 1, 2016, 8:26 PM

            @paphko said in How to receive push notifications from another server?:

            On the openhab side, I can easily add some arbitrary java code, for example to perform some http requests or to open and communicate via a socket connection to a specific IP.

            in a module i forked from paviro, there is a functionality where you can make http requests to the module https://github.com/fewieden/MMM-syslog/blob/master/node_helper.js#L16

            Please create a github issue if you need help, so I can keep track

            P 1 Reply Last reply Sep 1, 2016, 9:13 PM Reply Quote 1
            • P Offline
              paphko @strawberry 3.141
              last edited by Sep 1, 2016, 9:13 PM

              @strawberry-3.141 Awesome, thank you! That’s exactly what I was looking for :-)

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