Alexa dot

Ethernet interface was used to connect to the internet and make a GET request to the server that would give a binary value to turn the LED on or off. Below is the pin layout for the ethernet interface.

/media/uploads/hbindra3/screen_shot_2016-10-31_at_1.33.31_pm.png

Introduction

Echo Dot is a hands-free, voice-controlled device that uses the same far-field voice recognition as Amazon Echo. Dot has a built-in speaker and also connects over Bluetooth or with the included audio cable—to your own speaker.

Technologies Used

  • C++ to write mbed code
  • NodeJs for amazon lambda function.
  • PHP for backend server hosted on AWS.

Getting started with Amazon Dot

You will need an amazon developers account to create an Alexa skill. Click on the link below to set up your own sample skill. After setting up your own skill, copy the code for the lambda function and paste it in the sample code you created in the previous step. Link: http://amzn.to/1STLu9X

How it works:

  • The user will ask Alexa to trigger our skill (application)
  • Amazon will process the speech and get the text.
  • In our intent, we will have phrases mapped to the function names that exists in our lambda function.
  • A function inside the lambda function will be triggered (turnOn/turnOff), which will then make a POST request to the server that will either set the flag to 0 or 1.
  • Mbed will be making a GET request from the server every 2 seconds and will turn on / turn off all the LEDs based on the flag value.

Code for lambda function:

var http = require('http')

exports.handler = (event, context) => {

  try {

    if (event.session.new) {
      // New Session
      console.log("NEW SESSION")
    }

    switch (event.request.type) {

      case "LaunchRequest":
        // Launch Request
        console.log(`LAUNCH REQUEST`)
        context.succeed(
          generateResponse(
            buildSpeechletResponse("Welcome to E C E 41 80", true),
            {}
          )
        )
        break;

      case "IntentRequest":
        // Intent Request
        console.log(`INTENT REQUEST`)

        switch(event.request.intent.name) {
          case "lightOn":
            var options = {
  host: 'www.YOUR OWN HOST.com',
  path: 'YOUR PATH',
  method: 'POST'
};

callback = function(response) {
  var str = '';

  //another chunk of data has been recieved, so append it to `str`
        response.on('data', function (chunk) {
        str += chunk;
        });

  //the whole response has been recieved, so we just print it out here
            response.on('end', function () {
                console.log(str);
                console.log("yes");
                context.succeed(
          generateResponse(
            buildSpeechletResponse("Turning on the lights", true),
            {}
          )
        )
            });
            }

            http.request(options, callback).end();
            
            break;

          case "lightOff":
              var options = {
  host: 'www.YOUR OWN HOST.com',
  path: 'YOUR PATH',
  method: 'POST'
};

callback = function(response) {
  var str = '';

  //another chunk of data has been recieved, so append it to `str`
        response.on('data', function (chunk) {
        str += chunk;
        });

  //the whole response has been recieved, so we just print it out here
            response.on('end', function () {
                console.log(str);
                console.log("yes");
                context.succeed(
          generateResponse(
            buildSpeechletResponse("Turning off the lights", true),
            {}
          )
        )
            });
            }

            http.request(options, callback).end();
            
            break;

          default:
            throw "Invalid intent"
        }

        break;

      case "SessionEndedRequest":
        // Session Ended Request
        console.log(`SESSION ENDED REQUEST`)
        break;

      default:
        context.fail(`INVALID REQUEST TYPE: ${event.request.type}`)

    }

  } catch(error) { context.fail(`Exception: ${error}`) }

}

// Helper method to turn text to speech
buildSpeechletResponse = (outputText, shouldEndSession) => {

  return {
    outputSpeech: {
      type: "PlainText",
      text: outputText
    },
    shouldEndSession: shouldEndSession
  }

}

generateResponse = (speechletResponse, sessionAttributes) => {

  return {
    version: "1.0",
    sessionAttributes: sessionAttributes,
    response: speechletResponse
  }

}

Demo video


Please log in to post comments.