Alexa Skills Demo on PSoC 6 Wi-Fi BT Prototyping Kit
The objective of this blog is to explain how to use Alexa Skills to control ‘things’ using PSoC 6 Wi-Fi BT Prototyping kit. We will control the speed of a fan on PSoC thermal management expansion board by instructing an Alexa device.
Figure 1. Data flow from Amazon Echo to the fan
Amazon Echo is tuned to our use case of controlling the speed of a fan by building a custom skill using Alexa Skills Kit.
The developed custom skill is hosted on AWS Lambda service. Lambda function is triggered from Alexa Skills and the function is coded to publish messages to a topic in AWS IoT based on the input from the developed custom Alexa skill.
The physical device (PSoC6 + 4343W) subscribes to this topic in AWS IoT and generates appropriate PWM signal to control the speed of the fan. In this project, we will operate the fan at three different speeds namely low speed, mid speed and high speed.
20% duty cycle (0 to 20% duty cycle will operate the fan in the kit at its minimum speed).
50% duty cycle
|High Speed||100% duty cycle|
However, in case of general instructions to Turn On/Off or increase/decrease of the speed, following will be the behavior.The user is expected to control the fan by asking Alexa to set or run at one of these speeds.
However, in case of general instructions to Turn On/Off or increase/decrease of the speed, following will be the behavior.
|Fan will run at mid speed|
|Turn Off||Fan will run at low speed|
|Increase the speed||Fan will run at high speed|
|Decrease the speed||Fan will run at low speed|
(Ensure default language is English (US).
Default settings allows us to create a custom skill and use our own AWS lambda endpoint)
Figure 2. Alexa Custom Skill Creation
4. Choose template as Start from scratch.
5. Start building the custom skill by
a. Entering an invocation name – ‘fan controller’ is used in this project. This name is required for launching our custom skill.
b. Adding custom intents and utterances –
We will add an intent for each of the three speeds that we intend our fan to operate at,
namely LOW_SPEED, MID_SPEED and HIGH_SPEED.
Add all those phrases the user might utter to achieve the intent’s functionality as its sample utterances.
Either create the intents from the GUI in the developer console or use the provided JSON file (intents.json) and copy paste
the contents in the JSON editor tab.
c. ‘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.
We will return to the Alexa developer console and add the ARN of the lambda function we create in Section 4.2.
Refer to Alexa documentation for developing custom skill for more detailed explanation of creating custom skills.
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.
Follow the instructions in the amazon documentation 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).
Leave the rest at default.
5. Modify the lambda function to interact with the ‘thing’ related data in AWS IoT.
a. Insert Endpoint of your ‘thing’ from the IoT AWS core.
Navigate to Things -> Interact and choose the REST API endpoint in the IoT AWS core.
Figure 3. Thing Endpoint in lambda function
b. Change the ‘thing’ name in the lambda function per the thing created in AWS IoT as shown below.
Figure 4. Thing name in lambda function
6. Copy the ARN of your lambda function. 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.
We need to create an IAM policy that provides the minimum required permissions for Alexa Skills to invoke an AWS Lambda function.
Figure 5. IAM Roles
(*Exact screenshots may differ)
3. Click the policy name under permissions tab. Choose Edit policy.
Go to JSON tab and copy the content from the attached policy (IAM policy.json).
Click on review policy -> save policy.
1. Install Mbed CLI and Mbed Serial Port driver. Refer to for more details.
2. Use the PSoC 6 +4343W Prototyping kit in DAPLink mode. Hold SW3 switch for >2 seconds and release.
The status LED (LED2) should ramp up an amber light at 2Hz.
If you face any issues in entering DAPLink, ensure the kit has latest KitProg3 firmware.
Refer touser guide for more details.
3. Clone the Code example ‘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.
4. Enter the subscriber directory and follow the Instructions below to build AWS IoT subscriber code example.
a. Change 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
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.
Use the attached sample_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 toon 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 zipand 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.
i. Modify the default AWS packet size to high value.
This is needed to receive the entire message from the shadow and then extract the required state in our subscriber application.
This macro is available in
Modify AWS_MAX_PACKET_SIZE to 1000 as shown.
By default, it is set to 100.
Figure 6. Increasing AWS Packet Size
j. Build the project using mbed compile --target CY8CPROTO_062_4343W --toolchain GCC_ARM
k. Hex file generated can be found in
Program the hex file using Cypress Programmer or drag and drop the hex file to the DAPLINK drive.
Alternately, use mbed compile --target CY8CPROTO_062_4343W --toolchain GCC_ARM -f to compile and program.
CY8CPROTO-062-4343W kit is connected to CY8CKIT-036 as shown.
DGND of both the kits are connected. PWM signal for fan 1(PWM1) is connected to P8.7 in this example.
Figure 7. Hardware set up
Ensure to select the same language as in Amazon developer account is selected in Alexa Mobile App while setting up the Amazon Echo device.
Refer to the Amazon documentation for more details on testing the custom the skill.
In these examples, fan controller is the invocation name.
This must be used in the sentence to launch the custom skill along with connection words such as ask,tell, from etc.
Refer to Alexa Documentation for more details on how to invoke custom skills.
2. Echo device/simulator should respond back with the speed at which the fan is running.
Note: If expected behavior is not observed when using the Echo device,
please check if Alexa was able to process your speech correctly.
In the Alexa App, Navigate to Settings -> Alexa Privacy -> Review Voice History to check your interactions with Alexa.
3. Alexa Simulator Output
Enter test tab and type the utterance. Alexa skills responds with the output as shown in figure below.
Figure 8. Alexa test (Simulator)
4. AWS IoT Output
Enter the activity tab and observe the shadow state being updated as shown.
Figure 9. AWS IoT shadow
5. Serial Terminal Output
Figure 10. Tera Term Output
Thank you! Enjoy controlling physical devices using PSoC 6 + 4343W through Alexa!