-
1Building Custom Alexa Skill
For working with amazon services you will need to have an account for AWS cloud. I am assuming you have already an account.
1. Login Amazon developer account and navigate to Alexa developer console.
2. Click on Create skill.
3. Enter a name for the skill and leave the rest at default as shown in following Figure. (Ensure default language is English (US). Default settings allows us to create a custom skill and use our own AWS lambda endpoint)
4. Choose hello world template and click on Continue with template.
5. Start building the custom skill by
a. Entering an invocation name – ‘talking home’ is used in this project. This name is required for launching our custom skill.
b. Adding custom intents and utterances –
We will add a separate intent for controlling each of the device that we want to operate with our voice command. For adding a new intent click on Add Intent
Put an intent name and click on Create custom intent
Add all those phrases the user might utter to achieve the intent’s functionality as its sample utterances. (e.g. suppose a user wants to turn on the kitchen light, then the user may ask: turn on the kitchen light, turn the kitchen light, kitchen light on, make kitchen light on etc.)
You can create the intents from the GUI in the developer console shown in the above step or use the provided JSON file (intents.json) and copy paste the contents in the JSON editor tab directly.
c. After creating all the intents ‘Save model’ followed by ‘Build Model’ and ensure error free build.
d. Test your model by using ‘Evaluate model’. Entering a sample utterance should invoke the correct intent.
e. Go to Endpoints -> Choose AWS Lambda ARN. Copy the skill Id. This is required in the AWS Lambda services configuration.
After creating Lambda function we will get an ARN. We will return to the Alexa developer console and add the ARN of the lambda function we create in Alexa Skill endpoint.
Refer to Alexa documentation for developing custom skill for more detailed explanation of creating custom skills.
-
2Configuring the AWS IoT Core service
Login to AWS console. Go to the AWS IoT Core.
AWS IoT Core requires the following to be set up
1. Things - Things refer to a representation of the physical device.
2. Certificates - Certificates should be created to ensure secure communication between AWS and the device.
3. Policies - you must create and attach an AWS IoT policy that will determine what AWS IoT operations the thing may perform.
Things Setup
a. Go to AWS IoT Core service and from the Manage tab click on Things and then choose Register a thing
b. Select Create a single thing and provide a thing name, keep other thing untouched and click on next
Certificate Setup
a. After creating a thing your next task is to create certificate for the thing. For creating certificate click on Create certificate
b. Your certificate will be created. After creating certificate you need to download all the certificate file. You will required all these for PSoC programming.
Attaching a Policy
Now you need to attach a policy for the thing giving necessary access permission
- In the AWS IoT console, if a Get started button appears, choose it. Otherwise, in the navigation pane, expand Secure, and then choose Policies.
- If a You don't have any policies yet dialog box appears, choose Create a policy. Otherwise, choose Create.
- Enter a name for the AWS IoT policy (for example, psoc_policy). Add the json text and click on Create.
I have already created a policy and added this policy to the thing.
From IoT things page you can choose already created policy and then click on Register Thing. You AWS IoT thing will be created syccessfully.
Follow the instructions in the amazon documentation for more to create things, certificates, policies and attach the policies to certificates.
Ensure to have same region selected for AWS lambda and AWS IoT core.
Regions can be selected at the top right corner in both the consoles. N.Virginia (US EAST region was selected in this project).
-
3Creating Lambda function
- From AWS home page, open lambda services by navigating through Services -> Compute -> Lambda and click on Create function.
2. Choose to create function -> Author from scratch and Enter a function name.
Choose Node.js 12.x for Runtime.
3. Leave ‘choose/create execution role’ at default (i.e create a new role with basic lambda permissions).
4. Once the function is created, click on Add trigger and choose Alexa Skills Kit.
5. Enable skill id verification and paste the copied skill id from the Alexa skills endpoint section.
6. Click on Lambda function name and Scroll down to the code function area and copy the code provided as index.js to the console
7. Modify the lambda function to interact with the ‘thing’ related data in AWS IoT.
a. Insert Endpoint with your own ‘thing’ endpoint from the IoT AWS core.
Navigate to Things -> Interact and choose the REST API endpoint in the IoT AWS core.
b. Change the ‘thing’ name in the lambda function per the thing name created in AWS IoT as shown below.
8. Copy the ARN of your lambda function. Go back to Alexa developer page and add this to the default region of AWS Lambda ARN in the Alexa Skills Endpoint.
This is required for invoking this lambda function when the user interacts with ASK
-
4Creating Subscriber Application for PSoC 6 WiFi-BT Pioneer Kit
Before going to coding you need to update the device firmware. Cypress have released a tool to update the firmware on their boards. By default, these boards come with KitProg2 installed, but we need KitProg3 (Refer to KitProg3 user guide for more details). Download the latest release from their GitHub repository depending on which OS you run, and unzip it. Connect your board to the PC, and navigate to the bin/ folder inside the extracted folder. Run the command promote and type and run the following command
fw-loader.exe --update-kp3
Once this is complete you will get the following confirmation
Now you need to change the mode to DAPLINK mode. To do so, you can either push the "MODE" button to get it into DAPLINK mode. Or, you can simply run
fw-loader.exe --mode kp3-daplink
The device should appear as a USB drive name as DAPLINK. From now on, all you need to do to update the code running is simply drag and drop the downloaded .hex file into the USB drive. It will automatically self-program and then delete the .hex from the USB interface.
1. Install Mbed CLI and Mbed Serial Port driver. Refer to Mbed documentation for more details.
2. Clone the Code example ‘mbed-os-example-aws-iot-client’ using the following command.
mbed import mbed-os-example-aws-iot-client
This example connects to a WiFi network and can subscribe to messages from the AWS cloud using the Mbed OS ecosystem from github.
3. Enter the subscriber directory and follow the Instructions below to build AWS IoT subscriber code example.
a. Move to the application folder (subscriber)
b. Prepare the cloned working directory for mbed by entering the following command in command prompt.
mbed config root
c. Pull the necessary libraries and its dependencies.
This will pull mbed-os, AWS_Iot_Client library and its internal 3rd party dependencies. Type
mbed deploy
d. Configure the SSID and password of the desired network in the mbed_app.json file.
Replace the word ‘SSID’ with name of the network and similarly for the password.
e. Configure the AWS parameters such as Thing name, certificates, private key per the user's AWS account in aws_config.h file.
Use the attached aws_config.h for reference.
f. Also, configure the AWS topic to be subscribed to receive the messages.
The lambda code provided in the example updates to shadow of the ‘thing’.
We will subscribe to the ‘shadow delta’ to receive the messages.
Refer to Amazon Documentation on shadows for more details.
g. We receive messages from AWS thing shadow in JSON format.
We will use a JSON library to extract the desired state from the JSON formatted message.
Download the zip JSON parser and extract the contents.
Create a folder, say mbed-json-parser inside the subscriber folder and place the extracted .cpp and .h files in that folder.
h. Replace the subscriber.cpp file in the subscriber folder with the subscriber.cpp file provided in the file section.
i. Modify the default AWS packet size to high value in aws_client.h.
This is needed to receive the entire message from the shadow and then extract the required state in our subscriber application.
Modify AWS_MAX_PACKET_SIZE to 1000 as shown.
By default, it is set to 100.
j. Build the project using the following command
mbed compile --target CY8CKIT_062_WIFI_BT --toolchain GCC_ARM
k. Hex file generated can be found in
…\mbed-os-example-aws-iot-client\subscriber\BUILD\CY8CKIT_062_WIFI_BT\GCC_ARM.
Program the hex file using Cypress Programmer or drag and drop the hex file to the DAPLINK drive.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.