Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendNotification from external process... #268

Closed
desq42 opened this issue Apr 29, 2016 · 16 comments
Closed

sendNotification from external process... #268

desq42 opened this issue Apr 29, 2016 · 16 comments

Comments

@desq42
Copy link

desq42 commented Apr 29, 2016

Hi,

I´m fairly new to the whole node/socket thingy, but I´m wondering if it´s possible to send
a notification from an external process outside the MagicMirror Universe.
Specifically I would like to send a Notification from MotionEye, which has the ability to call a URL if it detects a Movement. This notification could perhaps show a picture of your frontdoor etc...
Perhaps somebody can give me a hint, if somethings like this would be possible, so I can dive into it.

Thank you.

@desq42 desq42 changed the title sendNotification from external processes… sendNotification from external process... Apr 29, 2016
@nhubbard
Copy link
Contributor

nhubbard commented Apr 29, 2016

You would probably use the NodeHelper to expose a URL, which MotionEye calls as a WebHook, triggering the notification. I'm not the utmost expert on this, but this should be the correct solution.

@desq42
Copy link
Author

desq42 commented Apr 29, 2016

I got the same idea. A node_helper is already working... I´ll keep you posted.

@MichMich
Copy link
Collaborator

MichMich commented Apr 29, 2016

One simple solution could be:

(in your node helper)

    start: function() {
        var self = this;
        this.expressApp.get(this.name + '/foo', function (req, res) {
            res.send('OK');
            self.doSomething();
        });
    },
    doSomething: function() {
        // Do something here, like sending a socket message to the frontend.
    }

You could now invoke the doSomething() method by calling: http://localhost:8080/modulename/foo.

(Code is not tested, but something like the above should work ...)

@desq42
Copy link
Author

desq42 commented May 2, 2016

start: function() {
    var self = this;
    this.expressApp.get(this.name + '/foo', function (req, res) {
        res.send('OK');
        self.doSomething();
    }
},
doSomething: function() {
    // Do something here, like sending a socket message to the frontend.
}

Thanks for the Code-Snippet. Missing ")" bracket after ´/foo´?
I´m getting a "Cannot GET /urlserver/foo", if I´m calling the URL.

@MichMich
Copy link
Collaborator

MichMich commented May 2, 2016

Sorry, missing ); below the self.doSomething(). Fixed it in my example.

@desq42
Copy link
Author

desq42 commented May 2, 2016

Thanks. I´m still getting a "Cannot GET /urlserver/foo" from my browser when I´m calling the url.
No "doSomething()" invoked.

@MichMich
Copy link
Collaborator

MichMich commented May 2, 2016

What is the exact url you are calling?

@desq42
Copy link
Author

desq42 commented May 2, 2016

I´m running the whole thing on my mac. so : http://localhost:8080/urlserver/foo

@MichMich
Copy link
Collaborator

MichMich commented May 2, 2016

and urlserver is the exact name of your module?

@desq42
Copy link
Author

desq42 commented May 2, 2016

correct.

@MichMich
Copy link
Collaborator

MichMich commented May 2, 2016

Should work. You could try debugging by checking all registered routes, using something like:

console.log(this.expressApp.stack);

(Not sure of that works ...)

@desq42
Copy link
Author

desq42 commented May 2, 2016

okay. now it works. here is my node_helper code. - the problem was a missing "slash" in the path;
(BTW How do I tag my code correctly for viewing?
bildschirmfoto 2016-05-02 um 15 50 52
(the insert code tag doesn´t work for me)

`
var NodeHelper = require("node_helper");
var express = require('express');
var app = express();

module.exports = NodeHelper.create({
start: function () {
var self = this;
this.expressApp.get('/' + this.name + '/foo', function (req, res) {
res.send('Welcome');
self.doSomething();
});
},
doSomething: function() {
console.log("Called!");
this.sendSocketNotification('URLSERVER'," called!");
}
});
`

@desq42 desq42 closed this as completed May 2, 2016
@desq42 desq42 reopened this May 2, 2016
@MichMich
Copy link
Collaborator

MichMich commented May 2, 2016

use:

    ```javascript
    // your code here
    ```

@MichMich
Copy link
Collaborator

MichMich commented May 2, 2016

Would it be ok for you to proceed any further discussion of this issue on: https://forum.magicmirror.builders? This way I can limit the use of GitHub issues to bug reports.

@desq42
Copy link
Author

desq42 commented May 3, 2016

Of course. Thanks for your assistance.

@desq42 desq42 closed this as completed May 3, 2016
@khaerulumam42
Copy link

Hello @desq42 , I want add face recognition based-on this model from external process and then send notification to MagicMirror. Could you share your program code as you discussed above?

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants