Page 2 of 9

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 3:05 am
by wyowolf
Not sure what I did wrong, but I got this error msg when i hit the "test" button...

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 11:31 am
by JonW
Sounds like there's probably a bad character in the code which is generating the "Unexpected token ILLEGAL" message. If you edited the JSON data at the end of the file for your devices, it is quite easy to make an error there.

Also, what did you configure for a test event? Pressing the test button requires you put code there that would call your function with a valid trigger event.

Here's an example test event that would turn on Process 0. You can cut and paste this into the test event code section.

Code: Select all

{
  "header": {
    "namespace": "Alexa.ConnectedHome.Control",
    "name": "TurnOnRequest",
    "payloadVersion": "2",
    "messageId": "4c6d29b1-b884-4fe2-a077-8b89d96e573e"
  },
  "payload": {
    "accessToken": "111222333444555666777888999000",
    "appliance": {
      "applianceId": "PROCESS_0",
      "additionalApplianceDetails": {
        "extraDetail3": "(not used)",
        "extraDetail4": "(not used)",
        "extraDetail1": "(not used)",
        "extraDetail2": "(not used)"
      }
    }
  }
}

When debugging code from the Lambda editor, you can look at your execution logs for more detailed information. Click on "Monitoring", then "View logs in CloudWatch".

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 2:09 pm
by wyowolf
Ok will try to be as detailed as I can.

On the code, I simply cut and pasted whatever you wrote in the beginning. The only change I made was to add my BCS IP address where indicated.. I made NO other changes.

ok I cut and pasted your test event and got a different error.

{
"errorMessage": "Unexpected token ILLEGAL",
"errorType": "SyntaxError",
"stackTrace": [
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)"
]
}

and this is from the "cloud watch"

2017-03-15 21:04:19
START RequestId: c0be9486-09c2-11e7-8460-43d184303956 Version: $LATEST
Syntax error in module 'index': SyntaxError
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
END RequestId: c0be9486-09c2-11e7-8460-43d184303956
REPORT RequestId: c0be9486-09c2-11e7-8460-43d184303956 Duration: 3.99 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 16 MB

I ran this test twice to make sure...

thank you very much for your help!

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 2:10 pm
by wyowolf
this is where I added my local IP to the BCS.

var AWS = require('aws-sdk');
var http = require('http');

var host = 'bcs.demohost.org'; \\ 192.168.1.130
var port = '46001';
var user = 'admin:control';

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 3:25 pm
by JonW
There's two issues here. The first is that the comment on the "var host" line has the slashes going the wrong way. Should be "//". However, there's another possible issue in the function that calls the BCS.

Instead of messing with tracking it down, I've updated the code in the first post to use the most current version that I am using. This version was rewritten to streamline a bit, but also to add the ability to ask Alexa what the current temperature is of devices. The temp request code is still being worked on a bit, but all the control features works well.

Copy the new code file into your function and do your testing on that.

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 3:52 pm
by wyowolf
ok thank you very much!!

I entered my IP and Port settings, but Im not sure what i put for BCS credentials?

var host = 'www.demo.com'; // 192.168.1.130
var port = '46001'; // 80
var user = 'admin:control'; // Change to your BCS credentials.

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 3:54 pm
by wyowolf
ok I ran it and got this

{
"errorMessage": "RequestId: 456490f0-09d2-11e7-b0cb-4f508196fe50 Process exited before completing request"
}

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 3:57 pm
by wyowolf
from the log

START RequestId: 456490f0-09d2-11e7-b0cb-4f508196fe50 Version: $LATEST
2017-03-15T22:53:57.130Z 456490f0-09d2-11e7-b0cb-4f508196fe50 ********** Event Request **********
2017-03-15T22:53:57.131Z 456490f0-09d2-11e7-b0cb-4f508196fe50 {"header":{"namespace":"Alexa.ConnectedHome.Control","name":"TurnOnRequest","payloadVersion":"2","messageId":"4c6d29b1-b884-4fe2-a077-8b89d96e573e"},"payload":{"accessToken":"111222333444555666777888999000","appliance":{"applianceId":"PROCESS_0","additionalApplianceDetails":{"extraDetail3":"(not used)","extraDetail4":"(not used)","extraDetail1":"(not used)","extraDetail2":"(not used)"}}}}
2017-03-15T22:53:57.131Z 456490f0-09d2-11e7-b0cb-4f508196fe50 ********** Event Response **********
2017-03-15T22:53:57.131Z 456490f0-09d2-11e7-b0cb-4f508196fe50 {"header":{"namespace":"Alexa.Connectedhome.Control","name":"TurnOnConfirmation","payloadVersion":"2","messageId":"4c6d29b1-b884-4fe2-a077-8b89d96e573e"},"payload":{}}
2017-03-15T22:53:57.148Z 456490f0-09d2-11e7-b0cb-4f508196fe50 ********** BCS Request **********
2017-03-15T22:53:57.148Z 456490f0-09d2-11e7-b0cb-4f508196fe50 {"running":true}
2017-03-15T22:53:57.188Z 456490f0-09d2-11e7-b0cb-4f508196fe50 Error: connect ECONNREFUSED xxx.yyy.zzz.224:46001
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1062:14)
END RequestId: 456490f0-09d2-11e7-b0cb-4f508196fe50
REPORT RequestId: 456490f0-09d2-11e7-b0cb-4f508196fe50 Duration: 169.12 ms Billed Duration: 200 ms Memory Size: 512 MB Max Memory Used: 7 MB
RequestId: 456490f0-09d2-11e7-b0cb-4f508196fe50 Process exited before completing request

(edited by JonW to remove IP address)

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 4:03 pm
by JonW
Look where your error is: Error: connect ECONNREFUSED xxx.yyy.zzz.224:46001

Connection refused. Did you do the port forwarding on your firewall? Amazon is trying to reach out to your BCS at the IP/PORT specified and was denied connection.

Re: HowTo: Voice control of BCS with Amazon Alexa

Posted: Wed Mar 15, 2017 6:28 pm
by oakbarn
Does this example code jump right to the Process 0 State 3 or does the Process 0 already need to be asserted?

// This example command activates a specific state at Process 0, State 3.
// Jumping to, or starting a state only needs the "turnOn" action defined.
{
"applianceId": "CUSTOM_P0S3",
"friendlyName": "Mash in Rest",
"friendlyDescription": "Activate Mash Rest State",
"manufacturerName": "Embedded Control Concepts",
"modelName": "BCS",
"version": "2",
"isReachable": true,
"additionalApplianceDetails": {
"extraDetail1": "",
"extraDetail2": "",
"extraDetail3": "/api/process/0",
"extraDetail4": JSON.stringify({"current_state": 3})
},
"actions": [
"turnOn"
]
},