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

A bit more plumbing info please!? #11

Open
dcarroll opened this issue Apr 17, 2016 · 6 comments
Open

A bit more plumbing info please!? #11

dcarroll opened this issue Apr 17, 2016 · 6 comments

Comments

@dcarroll
Copy link

Would you mind putting in a bit of info on how to wire this up? Is there a lambda function that I need to write and deploy to AWS? How is the discovery process accomplished from the Echo side? This looks very promising as I have been researching and trying different solutions for a year. A bit of additional guidance would be greatly appreciated.

@sushilks
Copy link
Owner

This is not designed to work as a lambda function (Although it would have been nice).
The server code needs to be on the same network that the harmony remote is connected on. This is a requirement as there is no security/authentication build on the remote and it would be unadvisable to open it up on internet.

So the Application will run on a server (Linux or windows machine/VM) in your home network. The connectivity to Amazon is established by manually configuring AWS with the hostname of your server. (There is quite a bit of pain here in terms of configuring certificates on the server such that AWS will accept the connection, AWS does not allow unencrypted connections).
Between the Application and the Harmony HUB the configuration file will hold the ip address of the HUB which you will need to manually provide in a file.
There is a supporting CLI utility which can easily do the discovery and provide you with the IP adderss of the Harmony HUB.
I would encourage you to use the CLI to make sure things are working as expected by manually doing the discovery and executing some commands on it before trying the connection to Echo.

Hope this helps.

@rgauss
Copy link
Contributor

rgauss commented Apr 18, 2016

Also note that you can use 'real', free certs from Let's Encrypt rather than self-signed.

@dcarroll
Copy link
Author

Definitely helps! I've been monkeying around with Smartthings, Hue Bridge
on RPi, soooo many combos and I really don't want a lambda anyway. Thanks
for this work!

On Sun, Apr 17, 2016 at 5:08 PM, Sushil Singh [email protected]
wrote:

This is not designed to work as a lambda function (Although it would have
been nice).
The server code needs to be on the same network that the harmony remote is
connected on. This is a requirement as there is no security/authentication
build on the remote and it would be unadvisable to open it up on internet.

So the Application will run on a server (Linux or windows machine/VM) in
your home network. The connectivity to Amazon is established by manually
configuring AWS with the hostname of your server. (There is quite a bit of
pain here in terms of configuring certificates on the server such that AWS
will accept the connection, AWS does not allow unencrypted connections).
Between the Application and the Harmony HUB the configuration file will
hold the ip address of the HUB which you will need to manually provide in a
file
https://github.com/sushilks/alexaHarmonyApp/blob/master/remote_conf.js.
There is a supporting CLI utility
https://github.com/sushilks/harmonyHubCLI which can easily do the
discovery and provide you with the IP adderss of the Harmony HUB.
I would encourage you to use the CLI to make sure things are working as
expected by manually doing the discovery and executing some commands on it
before trying the connection to Echo.

Hope this helps.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#11 (comment)

Thanks,
Dave

@joezorry
Copy link

You can have a lambda that basically just send the requests to our own server, then you don't need to setup a https certificate on our own server.
You do have to modify the existing code a bit though.

@chasepeeler
Copy link

@joezorry Any details on how you would do that? I've got everything set up, but I can't get it to work in my network. I think the issue is that I'm using an Airport Extreme which doesn't do any sort of DNS, preventing the Echo from being able to connect to the webserver via hostname. I could NAT a request coming from an external server, which would get around that.

@joezorry
Copy link

@chasepeeler here is the redirect snippet I use for my AWS Lamda, you need to replace id and url

var http = require('http');
var URLParser = require('url');

exports.handler = function (json, context) {
    try {
        // A list of URL's to call for each applicationId
        var handlers = {
            'appId':'url',
            'amzn1.echo-sdk-ams.app.THIS_IS_YOUR_APP_ID':'http://someurl.com'
        };

        // Look up the url to call based on the appId
        var url = handlers[json.session.application.applicationId];
        if (!url) { context.fail("No url found for application id"); }
        var parts = URLParser.parse(url);

        var post_data = JSON.stringify(json);

        // An object of options to indicate where to post to
        var post_options = {
            host: parts.hostname,
            port: (parts.port || 80),
            path: parts.path,
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': post_data.length
            }
        };
        // Initiate the request to the HTTP endpoint
        var req = http.request(post_options,function(res) {
            var body = "";
            // Data may be chunked
            res.on('data', function(chunk) {
                body += chunk;
            });
            res.on('end', function() {
                // When data is done, finish the request
                context.succeed(JSON.parse(body));
            });
        });
        req.on('error', function(e) {
            context.fail('problem with request: ' + e.message);
        });
        // Send the JSON data
        req.write(post_data);
        req.end();        
    } catch (e) {
        context.fail("Exception: " + e);
    }
};

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

No branches or pull requests

5 participants