unityfire/alexa-ha

Cannot connect to OpenHAB end point ... please help!

Closed this issue · 8 comments

I've been trying to fix the following issue for hours and hours so hopefully someone can provide some insight into what's going wrong ...

Have it all set up so I can connect through externally on HTTPS the 'Alexa Tester' page, but it refuses to connect to the OpenHab end point on another server (tried with and without username/pswd). I am fairly positive that it is down to the inserted URL password based on errors, but despite matching them in the config.js file, server.js file and adding it into the "https://<external_url_and_port>/api/alexa-ha?password= it still errors.

Could someone have a look over the configs below and the error log and advising how to fix or how to disable the password in the URL please.

config.js

// AWS ASK password, randomly generated password to be included in the Skill's endpoint URL (i.e. '?password=XXXXXXXXXXXX')
config.password = 'LRT69TGH6Y';

server.js

var AlexaAppServer = require("../index.js");
AlexaAppServer.start( {
        app_dir:"apps",
        app_root:"/api/",
        port : 30001,
        httpsEnabled : true,
        httpsPort : 30000,
        privateKey:'myserver.key',
        certificate:'cert.crt',
        preRequest: function(json,req,res) {
          // Include password value from URL parameter, so Alexa-HA can validate it...
          json.password = req.param('LRT69TGH6Y').toString();

          // Extract the IP address of the client (handles IPv4 and IPv6)
          var IPFromRequest = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
          var indexOfColon = IPFromRequest.lastIndexOf(':');
          var address = IPFromRequest.substring(indexOfColon+1,IPFromRequest.length);
          json.remoteAddress = address;

        },
        postRequest: function(json,req,res) {
        }
} );

My error log shows exactly the same error each time which looks to relate to the URL password:


TypeError: Cannot read property 'toString' of undefined
at Object.AlexaAppServer.start.preRequest (/home/alexa/node_modules/alexa-app-server/api/server.js:12:50)
at Object.handle (/home/alexa/node_modules/alexa-app-server/index.js:101:69)
at next_layer (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/route.js:107:5)
at /home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:195:24
at Function.proto.process_params (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:251:12)
at next (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:189:19)
at next (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:166:38)
at Layer.staticMiddleware [as handle] (/home/alexa/node_modules/alexa-app-server/node_modules/express/node_modules/serve-static/index.js:55:61)
at trim_prefix (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:226:17)
at /home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:198:9
at Function.proto.process_params (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:251:12)
at next (/home/alexa/node_modules/alexa-app-server/node_modules/express/lib/router/index.js:189:19)
at IncomingMessage. (/home/alexa/node_modules/alexa-app-server/index.js:184:5)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:923:12)
at nextTickCallbackWith2Args (node.js:458:9)
at process._tickDomainCallback (node.js:413:17)

@Dizlem -

  • Try commenting out this section to start (i.e. skip password checking)
  • If the above helps add logging to study the differences...maybe special encoding of password characters..?
  • Make sure your running v4.x of NodeJS, I haven't tested others (i.e., IIRC 'node -version')

One of these SHOULD lead us in the right direction!

Also, after studying some other Alexa HA support requests, check your ~/node_modules/alexa-app-server/api/server.js and make sure this matches the config.js value, and maybe play with commenting/uncommenting this line as well as a temporary workaround.

json.password = req.param('password').toString();

Thank you for coming back to me so quickly. Have had to be away from the computer all day, but have managed to play around this evening.

If I comment out all the Pre-execution security checks in alexa-ha/index.js I can use the Alexa Tester and it allows me to submit and the session changes to "{ "launched": "true" } so some progress .... presumably its being received and not deciphered correctly, so some more investigation required - I may try a reinstall to see if I've inadvertently messed something up.

Following this step I was able to send Intent Requests, only there are now no errors in the error log but in the server to I now see following which indicates it wasn't successful. I am however not sure if its actually reaching the OpenHAB server as the logs don't mention it just that it was unsuccessful.

I should also say looking around that I am running OH2 (I've made the HTTPS response change to 200) but I understand I should at least be able to connect and people have had quite a bit of success with it so far.


192.168.0.1 - 2015-05-13T12:34:56Z - AWS ASK IntentRequest received: amzn1.echo-api.request.-----my-id----- / amzn1.echo-api.session.-----my-id-----
REQUEST: Switch Intent slots are: ON/Light_GF_Hallway_Ceiling/Hallway
RESPONSE: I cannot currently switch your Hallway Light_GF_Hallway_Ceiling


This may of course be my configuration error, should the OpenHab item name I used be used in response?

Glad you managed to make some progress here!

"presumably its being received and not deciphered correctly, so some more investigation required - I may try a reinstall to see if I've inadvertently messed something up."

I don't think that's necessary as you've made it this far :) Next steps are to dig into your configuration.

"This may of course be my configuration error, should the OpenHab item name I used be used in
response?"

As you suspected, that looks to be a configuration error. The request is hitting your server, but Alexa HA is unable to match the command to a config item/room. I would suggest making the config as simple as possible to start (i.e. following the examples in config_default.js). If that doesn't help please share a sample of your config and I would be happy to help you get up 'n going!

.

Further investigation ... I'm pretty positive that it's not hitting my OpenHAB server. I can change or comment out the IP address in /alexa-ha/config.js (and restart the node server) and still get the Alexa Tester to update session to "{ "launched": "true" }, so assume this must refer to the alexa-ha app connection rather than to a remote end point. I also don't get any errors just the standard launch text in the server out log

The Alexa-HA server is a standalone server but I know my OpenHAB server is reachable from my Alexa-HA server


alexa@ALEXA-HA-01:~/node_modules/alexa-app-server/api/apps/alexa-ha$ nc -v -z -w2 ---openhab-ip--- 8080
OpenHAB-01.home.gateway [---openhab-ip---] 8080 (http-alt) open


I also built the string manually in config.js to see if that helped and it works from my browser but not makes no difference:

config.HA_server = 'http://user:pswd@---openhab-ip---:8080';

How can I check Alexa-HA is connecting to my OpenHAB server?

I see...

"The Alexa-HA server is a standalone server but I know my OpenHAB server is reachable from my Alexa-HA server"

Excellent, that is vital :)

I did have some issues with the Alexa Tester console a while back and would suggest relying on issuing real commands on your Echo(s) to validate your setup. For instance:

"Alexa, tell [invocation name] to turn on the HALLWAY LIGHTS"

Once the command reaches Alexa HA, it will show up in your Alexa HA nodejs logs (which it looks like is already happening above). Alexa HA will then issue the command to OpenHAB's REST endpoint ONLY if it found a match based on the configuration. If you are still seeing something like 'RESPONSE: I cannot currently switch your Hallway Light_GF_Hallway_Ceiling' then configuration is likely not matching (i.e. the getState check against OpenHAB server is not returning a good result)... To debug that you should uncomment the many console.log lines to dig deeper.

To monitor the activity on the OpenHAB side, tail your OpenHAB server logs to see the item/command is being received from your internal Alexa HA server IP.

Feel free to PM me your specific config details to me on https://community.openhab.org, or PM me to setup a screen sharing session and we will get this resolved out one way or another!

Thanks very much for your help to date. More investigation to sort out the problem but I also note I must use 443 outbound from ASK and that it doesn't support SNI which means I need to look at another route anyway as I host on 443 and although I use HAProxy the lack of SNI support will make the solution unworkable.

Looks like I may be investigating a Lambda setup instead.

Understood. These are Amazon imposed limitations which we can't do much about, but I can say I've been able to proxy the SSL connection from an existing Apache webserver - so Alexa-HA isn't directly exposed to the wild yet works over my pre-existing SSL certs/servers securely.

If you do go the Lamdba route, I am very interested hear the outcome. Glad to help with that too!