I'm trying to control my raspberry using Amazon Alexa, IoT and Lambda. What I got working so far:
- Setting up raspberry as IoT device and being able to publish and subscribe to a topic (Testes using the IoT Client)
- Setting up a test lambda node.js script
- Setting up a test Alexa Skill that triggers an intent in my lambda script
Here's the intent handling in my node.js script:
switch(event.request.intent.name) {
case "testone":
var config = {};
config.IOT_BROKER_ENDPOINT = "restAPILinkFromIoT".toLowerCase();
config.IOT_BROKER_REGION = "us-east-1";
//Loading AWS SDK libraries
var AWS = require('aws-sdk');
AWS.config.region = config.IOT_BROKER_REGION;
var iotData = new AWS.IotData({endpoint: config.IOT_BROKER_ENDPOINT});
var topic = "/test";
var output = "test output without publish"
var params = {
topic: topic,
payload: "foo bar baz",
qos:0
};
iotData.publish(params, (err, data) => {
if (!err){
output = "publish without error"
this.emit(':tell', tell);
} else {
output = err
}
});
context.succeed(
generateResponse(
buildSpeechletResponse(output, true),
{}
)
)
break;
...
Basically the script should either return "publish without error" or the error message. The Problem it always returns "test output without publish". It seems like the publish function (or at least the callback function) is never triggered. I also don't see a message in the topic.
Am I doing something wrong?
Thanks in advance!