How to add peripherals to AWS IOT and Alexa Skills

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to add peripherals to AWS IOT and Alexa Skills

How to add peripherals to AWS IOT and Alexa Skills

Introduction

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 165 fully-featured services from data centers globally. Millions of customers —including the fastest-growing startups, largest enterprises, and leading government agencies—trust AWS to power their infrastructure, become more agile, and lower costs.This document will take you step-by-step in a simple approach to adding peripherals to your AWS IOT and Alexa skills project. This is in continuation of the demo established in the following link, it is important to have this completed before continuing with this guide:

Connecting the LPC55S69 to Amazon Web Services 

Prerequisites

- LPC55S69-EVK

- Mikroe WiFi 10 Click

- AWS Account

- Alexa Developer Account

- MCUXpresso IDE 11.2

- LPC55S69 SDK 2.8.0

Modifying "AWS_REMOTE_CONTROL_WIFI"

In this example I will be adding a single-ended ADC peripheral.

1. First, create a separate .c and .h files in my source folder to keep it organized. 

pastedImage_16.png

2. Initialize your peripheral. This includes your global variables, pins, clocks, interrupt handlers and other necessary peripheral configurations yours may have. 

In my new_peripherals.c file, I add the following

2.1 Definitions:

pastedImage_18.png

2.2 Global variables:

pastedImage_20.png

2.3 Interrupt handler:

pastedImage_22.png

2.4 Initialization function:

pastedImage_24.png

2.5 Read ADC Function:

pastedImage_26.png

3.  Create header file with the two functions that will be used to enable the ADC, make sure to include the "fsl_lpadc"drivers.

pastedImage_28.png

4.  Add the ADC pin with pin configuration tool. 

pastedImage_1.png

4.1 In this example I use PIO0_23 for the ADC0 Channel 0,

pastedImage_3.png

5. Add ADC_Init function to the main.

pastedImage_5.png

6. Now let's go ahead and modify "remote_control.c". Here we need to build the JSON text that we want updating our Thing's shadow with the ADC value, add the read function, add the variable in the initial shadow document and the keyword for our DeltaJSON.

6.1 First create global variables for the actual state of the ADC interaction and the parsed state.

pastedImage_7.png

6.2 Add external function which will read the ADC value.

pastedImage_9.png

6.3 Shadows use JSON shadow documents to store and retrieve data. A shadow’s document contains a state property that describes these aspects of the device’s state:

  • desired: Apps specify the desired states of device properties by updating the desired object.
  • reported: Devices report their current state in the reported object.
  • delta: AWS IoT reports differences between the desired and the reported state in the delta object.

pastedImage_11.png

6.4 I've added the initial ADC state with a hard-coded 0, so that I can verify my Thing's shadow is initialized with the new information.

pastedImage_17.png

6.5 In the "void processShadowDeltaJSON(char *json, uint32_t jsonLength)" function, we need to add the condition for the change in state of the ADC. This will helps us identify when the action to read the ADC is requested.

pastedImage_20.png

6.6 Finally in the "prvShadowMainTask" function, we will create the action based on the above request. We can add some PRINTFs so that we know that the action is requested and processed properly through the serial console.

pastedImage_22.png

As you may see I only want to update the ADC value when it is requested. Meaning the value of the ADC's state or parsed state is important. We will clear it to zero after we read the ADC and only update the value when it is 1. As opposed to the LEDState and parsedLEDState, where the value is important since it points to which color LED will be on/off.

That's it you can build and run the project! Now we can add the Alexa Skill and the functionality in the AWS Lambda.

MODIFYING AWS LAMBDA

Since the lambda will be the connection between our LPCXpresso board and the Alexa Skill, we need to add the handler for  our new ADC requests.

1.  In this example we add the third request type which is the ADC event and the name of the callback function we will use. 

pastedImage_4.png

2. The callback function "manage_ADC_request" will contain the attributes for reading and updating the shadow, this will consequently cause the change in delta shadow so our LPC55S69 will read the ADC pin. In addition, the utterances sent to the Alexa skill as well as how we want Alexa to respond will also be defined here. 

pastedImage_2.png

As you may observe our function builds the JSON payload to update the shadow with a "1" when it is called and ignores the led and accelerometer values. We delay for 2.5 seconds to allow the LPC to read and write the ADC value in the necessary field and send the updated shadow. Then the Lambda will read the shadow and create the return message. 

With this we construct the answer for Alexa.

MODIFYING ALEXA SKILLS

1.  First create a custom 'intent'. Here is the general definition of what the utterances will be to request an action from the AWS Thing.

pastedImage_2.png

   1.1 The name needs to match the name used for the event in the Lambda. In this example it is ADC_INTENT

pastedImage_9.png

2. Before we create the utterances, let's create the slot types. This is the list of all the words possible that may come to mind that a user might say to request a reading from the ADC. 

pastedImage_11.png

2.1 The name of the slot type is not crucial, however please note it as we will need it later. 

pastedImage_13.png

2.2 Add slot values. You can add as many as you think are necessary. For recommendations on custom slot values please check, best practices for sample utterances.

pastedImage_15.png

2.3 Go back to the general view of the ADC_INTENT, scroll down and we will add how the slot will be included in the utterances. In this example I use adc_name, however the name here is also not crucial.

pastedImage_17.png

Select the slot type list we created earlier.

pastedImage_19.png

2.4 Now scroll back up and lets begin adding the sample utterances. This can be any command that you believe a user can say to invoke this action. You do not need to include the wake word here. In brackets add the name of your intent slot, in this case it is {adc_name}.

pastedImage_21.png

That's it! You can save and rebuild the model. You are now ready to test it. You can do so through the 'Test' tab on the developer's console. In addition if you have an Alexa device or the SLN-ALEXA-IOT, you can test it by speaking with Alexa directly. In your LPCXpresso55S69 you can connect the 3.3V or the 0V to the ADC pin so you can see how the value is returned every request. 

Labels (4)
Attachments
No ratings
Version history
Last update:
‎08-15-2020 10:01 AM
Updated by: