Dieses Blog durchsuchen

Seiten

Labels

Raspberry (8) RPI (8)

Donnerstag, 1. Februar 2018

Alexa communicates with Raspberry


All based on Raspberry Zero W with an "Debian Stretch" installed!

It takes a little bit of knowledge to connect Alexa to the Raspberry.
The most important thing to know is that the echo is quite stupid and almost does not do it on its own.
The echo only responds to the keyword Alexa and then sends the spoken word to the server.
As in our case the communication looks, I show here in a small diagram.

 

As we can see, Raspberry has to be reachable over the internet, with the Fritzbox you can do it easily.
After that we have to forward the port 443 for SSL to our Raspberry,
for this we have to use the standard port because Amazon is very bitchy and only allows SSL over 443. (Grrrr)
When we reach our PI over the Internet via ssl, we can get started on Skill development.

First we register at https://developer.amazon.com and then go to Alexa and to "Get Started".


Next, we'll start a new skill..


In my case, the skill is called Yoda and is German.


After saving we come to the "interaction model"

To test I enter in the "Intent schema" the following:
{
  "intents": [
    {
      "intent": "AMAZON.CancelIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.PauseIntent"
    },
    {
      "intent": "AMAZON.ResumeIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "MeinIntent"
    }
   ]
}

In the "Sample Utterances" I enter the following (it this case, its scrap but for testing it is enough ):

MeinIntent hallo wie gehts
MeinIntent hallo wie geht es dir
MeinIntent wie gehts
MeinIntent wie geht es


After saving, we come to the "Configuration" and enter the following, please note that you the Https address adapts to your!



Now we have to teach Amazon that our SSL certificate is accepted, since it is a self-singed certificate.

For this we take the content of certificate.pem that we already have as in the blog post
Lighttp and SSL have generated and copy the content into the input box.




So, now it's time to test!
We specified the endpoint under "Configuration" and now we have to fill it with life. 
Create the file yoda.php as follows:

pico /var/www/html/yoda/yoda.php

Now copy the following PHP code in.
 
<?php
header ("Content-Type: application/json;charset=UTF-8" );
http_response_code(200);
echo '{"version": "1.0","response": {"outputSpeech": {"type": "PlainText","text": "Am Ende sind Feiglinge die, die der Dunklen Seite folgen."},
        "card": {
            "type": "Simple",
            "title": "Am Ende sind Feiglinge die, die der Dunklen Seite folgen."
        }
       },"shouldEndSession": true}';

To test you call your HTTPS adress it in your browser (in my case i use Chrome).
Chrome shows a warning message because the certificate is "Self Signed". 
Confirm that he should load the page and the result should look like this.



Now we almost made it, only the final test is missing.



So, if now have a "Service Response" after clicking on "Ask Yoda", Alexa is connected to the Raspberry and all paths are open to us. Now go to your echo and say "Alexa start Yoda" and Alexa will answer you. :-)

Keine Kommentare:

Kommentar veröffentlichen