This document describes how to connect Amazon Echo to Gizwits IoT Cloud and control Gokit devices.
Collaboration diagram:
Integration Principle:
You can control Gizwits devices by calling Gizwits Open API with the Access Token returned when registering for your Gizwits Gokit App user account. Now that Gizwits Open API is also opened to Amazon users, who are able to link the Alexa Skill to their Gizwits Gokit App user accounts and call Gizwits Open API with corresponding Access Token required by Lambda so as to control devices via Open API.
Sequence diagram:
Highlights:
Follow Device Connection to Gizwits in the Document Center to connect the device to get the device did.
Follow App Connection to Gizwits in the Documentation Center to get the App ID.
Log in to Gizwits Developer Center and go to the product that needs to use the Product Interconnection Service. Choose Services - Add Services, and find the Product Interconnection Service. Click the [Apply] button, and wait for Gizwits to verify your request.
After the verification passes, you can see [Product Interconnection Service] in the service list; click [Product Interconnection Service] to use it.
Jump to the Product Interconnection Service page. Select the Amazon Echo tab and enter the App ID obtained in the above section, then click Configure.
Set the Client Name and Redirect URL of Alexa Skill.
Highlights:
1) Log in to the Amazon Developer Center.
2) Go to the Developer Console, click on the tab ALEXA, and click Get Started in Alexa Skills Kit.
3) Click Add a New Skill.
4)
5)Fill out Skill Information pane.
Then click Next.
Intent Schema defines an intent that represents an action that fulfills a user’s spoken request in JSON format.
One skill can have multiple intents. To define the voice interface, you map users’ spoken input to the intents your cloud-based service can handle. Intents can optionally have arguments called slots that represent variable information in the request.
There are two slot types:
For details, click here:
Set the Intent Schema as follows:
The Intent name is “ControlLight”, which has a Slot “LightState” of custom slot type “LIGHT_STATE”.
Then it pops up a window for us to input the slot type and its possible value. Type “LIGHT_STATE” for “Enter Type” and “on”, “off” for “Enter Values”, then click “Save”.
The sample utterances are set of likely spoken phrases mapped to the intents. Enter one utterance per line as follows:
1 | ControlLight Turn {LightState} the light |
The intent name is followed by a blank or tab, then followed by the user’s sentence. For the first line, it means that when the user says “Turn on the light”, it will invoke the ControlLight intent.
Then, press “Next”.
Select Configuration in the left navigation pane. Specify the endpoint for your skill. Alexa sends requests to this endpoint when users invoke your skill. You can choose to host your service as an AWS Lambda function or as a web service. Now, we need to skip this step and then come back after creating a AWS Lambda function.
Use Account Linking to create a link between the Alexa user and the user account in Gizwits.
Copy the Redirect URLs in the following picture to the Redirect URL field on the Product Interconnection Service page of Gizwits, where “Client Name” can be set to “Alexa”. Copy the Client ID and Client Secret values on the Product Interconnection Service page of Gizwits to the Client Id and Client Secret fields in the following picture respectively as unique public string used to identify the client requesting for authorization.
Input Privacy Policy URL as needed, then click Next.
Highlights:
If you do not already have an account on AWS, go to Amazon Web Services and create an account.
Log in to the AWS Management Console and navigate to AWS Lambda.
Click the region drop-down in the upper-right corner of the console and select US East (N. Virginia) supported for Alexa skills.
Select Services – Lambda.
If you have no Lambda functions yet, click Get Started Now. Otherwise, click Create a Lambda Function.
To start with sample code in Node.js or Python, click Blueprints, and select alexa-skills-kit-color-expert from the Alexa Skills Kit blueprints.
Choose Configure triggers. On this page, you can set the event that triggers the Lambda function. Click the dotted box in the middle, and a list of pre-defined services will appear. Here we select “Alexa Skills Kit” and click Next.
Choose Configure function. On this page, we need to provide the code related content. There are three fields:
In the Lambda function code, set the Code entry type. You can choose to write the code directly or upload the code. Here we select Edit code online.
Here first keep the sample code and we will come back and update the code.
Next set the Lambda function handler and role.
For “Handler”, keep the default value.
As “Role” is related to the permission of the Lambda function, we can set the permission of the Lambda function in order to prevent the Lambda function from using services that should not be used. In the drop-down list of “Role”, choose “Create a custom role”.
A new page will pop up and take you to the AWS IAM settings page, where set the “Role Name” to “control_light”. Then click on “View Policy Document”. Click “Edit” for the permissions of this role.
The edit the permissions of this role, you can see the default value is only for log permission. Since we need to use the AWS IoT permission, so we update it as follows.
Then click “Allow”.
Then the page closes and we go back to the previous Lambda function page. You can see that the fields for “Role” and “Existing Role” already have values.
For the Advanced settings, keep the default values, then click “Next”.
On the Review page, click “Create function”.
Now you have completed the setup. Please note that the string “ARN - arn:aws:lambda:us-east-1:xxxxxxxxxx” in the upper right corner is the endpoint of this Lambda function, which will be used in Alexa Skill settings page.
Go back to the AWS Lambda page, and choose the Code tab.
The onIntent function determines which intent handler will be used to process the intent request of “ControlLight” and dispatch to the function light_control.
In the light_control function, we can get the slot information of the intent. Here the slot we want to get is “LightState”.
Get the slot value of the intent and assign it to the variable switch_action. Then, if the switch_action is equal to on, pass True to the switch_action_fun function.
Then call Gizwits Open API to control the device. For details, please refer to the Open API guide.
Highlights:
Navigate to http://alexa.amazon.com/spa/index.html in your PC browser to set up your Amazon Echo.
Or use Alexa App to set up your Amazon Echo.
To download the Alexa app, go to the app store on your mobile device and search for “Alexa app.” Then select and download the app.
Log in with your Amazon account, go to the Alexa Settings page, and select your device.
Choose the language you use.
Click Connect to Wi-Fi.
Make sure your Echo device is plugged into a power outlet. When the light ring turns orange, click Continue.
Go to the Wi-Fi settings on your PC and select the network of the format Amazon-XXX to connect your PC to Echo.
After the following page appears, click Continue.
Select your Wi-Fi network and enter the network password (if required).
After your device connects to your Wi-Fi network, a confirmation message appears. Then click Continue.
Click Skills and jump to Your Skills page by clicking All Skills in the upper right corner. Choose Control GOKIT.
Click Enable.
Click Link Account.
Now jump to the login page, where you need to input the username and password registered with Gizwits Gokit App. Then click Sign in.
Then click Yes on the following page and the success message will appear as follows.
Go back to the Control GOKIT page and find that the Link Account button has disappeared, indicating that the Alex Skill was linked to Gizwits Gokit App user account successfully.
Highlights:
Go back to the Alexa page and click Configuration section. Enter the AWS Lambda ARN in the North America box. AWS Lambda ARN can be viewed in the upper right corner of the Lambda Function.
On the Test page, you can test your skill by using the Voice Simulator.
In Voice Simulator, you can test how Alexa will speak a response entered in plain text or SSML tags by clicking Listen button.
In Service Simulator, you can enter a plain text to simulate the words said by users, and let Alexa pretend to hear the message. Here input “Turn on the light”, then click “Ask Control Gokit”.
This message will be handled by Alexa and sent to the Lambda function. After processed by the Lambda function, the result will be returned. If the result is returned successfully, you can ask Alexa to control your Gokit.
You can listen to this result by clicking “Listen” in the bottom right corner.
Once you have completed testing on your device, please complete the Description and Publishing information tab, and then submit the skill for certification.
If it passes Amazon’s testing and certification process, it will become available to Alexa end users.
The skill is available in “Skills > Your Skills” page of the Alexa App. You can then enable the skill and test its functionality by asking Alexa.
If you encounter any problems during the publish process, contact Gizwits and we will help you.
Gokit is free, but only a limited number are available for individual developers. Register in our forum or follow our official WeChat to request for provision.
Community: http://club.gizwits.com/forum.php
Documentation Center: http://docs.gizwits.com/en-us/cloud/OpenAPI.html
Gizwits has a lot of support programs for organizations, you can contact Gizwits to get Gokit and timely technical support.
Website: http://en.gizwits.com/about-us
WeChat Official Account QR code of Gizwits: