Testing the project

For testing, we can use the Service Simulator section from the Amazon Alexa. You can find it on the Test menu from your Alexa skill. Follow the steps as follows:

  1. Fill turn on LED in the Enter Utterance field. You can see it in the following screenshot. Click on a button, for my case, it shows the Ask Smart LED button.
  2. After execution, the program will send a JSON message to AWS Lambda. Then, you should get a response from AWS Lambda. A sample of the response from AWS Lambda can be seen in the following screenshot:

If you have a response with outputSpeech I have received your order, it means that our program works.

  1. Now you open AWS IoT and run the Test program. Set alexa/led for subscribing a topic. Then, try to execute Service Simulator from Amazon Alexa. You should get a response with message on. You can also try to send  the message turn off LED on the Service Simulator:
  1. Now we can make a program to subscribe alexa/led on IoT board such as Raspberry Pi. When we receive the  on message from the AWS IoT, we can perform to turn on LED. Otherwise, we can perform to turn off LED when we receive the off message.
  2. For demo, I created a program to subscribe alexa/led. Once message is received, the program will print it on the console. Create the alexa-demo.js file and write this complete program for this demo:
var awsIot = require('aws-iot-device-sdk');

var device = awsIot.device({
keyPath: '<device>-private.pem.key',
certPath: '<device>-certificate.pem.crt',
caPath: 'cert/root-CA.pem',
host: '<iot-host>.iot.<region>.amazonaws.com',
clientId: 'user-testing',
region: '<region>'
});

device
.on('connect', function() {
console.log('connected');
device.subscribe('alexa/led');
});

device
.on('message', function(topic, payload) {
var order = payload.toString();
if(order=='on'){
console.log('turn on LED');
// perform turn on LED
//
}else{
console.log('turn off LED');
// perform turn off LED
//
}
});

console.log('AWS IoT - Alexa program started.');

This program is modified from Chapter 2, Connecting IoT Devices to the AWS IoT Platform. Once done, save this program and run it by typing the following command:

$ node alexa-demo.js
  1. You can test again to send speech commands from the Service Simulator section on Amazon Alexa. This program will receive that command. You can see a sample of program output in the following screenshot:

Finally, you have learned how to work with Amazon Echo and AWS IoT and make interaction. Next, you can learn about Alexa Skills Kit from the official document on https://developer.amazon.com/docs/ask-overviews/build-skills-with-the-alexa-skills-kit.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.215.96