Here's a tutorial to show you how to connect to AWS IoT with LinkITONE.
I made a small demo to make the tutorial more clear. A sensor and an actuator is need.
The demo will send a sensor data to AWS, and AWS was able to control the actuator as well.
Here we use Grove - Touch Sensor as the sensor while Grove - LED Bar act as the actuator.
Have fun, welcome to the world of IoT and AWS.
Step 1: Part List
Step 2: Configuring Your AWS IoT Service
At the very beginning, we need to get an AWS
IoT service account, and do some configuring.
Create an AWS Account
Go to AWS IoT and open the AWS IoT Dashboard
Sign in to your Account.
Click the Services on the top-left corner, and then click on AWS IoT, (image 1&2)
Click on Get Started. (image 3)
Then, we can create something now.
Click on Create a Resource and then create a thing (image 4&5)
Enter a name, whatever you like, here we name it LinkIt_AWS_Test. (image 6)
Click Create to complete it and then click on View thing to get information of the thing you create. (image 7)
Click on Connect a device. (image 8)
Choose Embedded C and Click on Generate certificate and policy. (image 9)
You will find 3 files. Download the file, we need them later. And click on Confirm & start connecting. (image 10)
Then we will get some code, as shown at below. Copy the code into an empty document. We will use code later. Then click on Return to Thing Detail. (image 11)
Now, this step is done. Let move to the next step.
Step 3: Setup Your LinkIT ONE Development Enviroment
Step 4: Download the Sketch/library
Put had on mbed TLS library for LinkIt ONE to view the github page.
Then click Download ZIP to download the code.
The code you downloaded is not an Arduino library, it's a sketchbook, which had included all the library the project need.
Unzip the file you had downloaded from Github, you will get a folder named aws_mbedtls_mqtt-master, remove “-master” in the file name.
Step 5: Configuring Arduino IDE
Open your Arduino IDE(1.5.7), click File > Preferences > Sketchbook Location, browse to the folder we had mentioned above - ArduinoPhone-master. Then click OK to save it.
Close and relaunch Arduino IDE, click File > Sketchbook > aws_paho_shadow, then the code will be opened.
Step 6: Put Key File Into Storage of LinkIt ONE
he application development for AWS IoT Services is performed in the Arduino IDE. Before commencing the sketch development add the certificates (.key or .crt files) created in section creating a certificate for a device or application communication into the LinkIt ONE development board’s flash storage memory as follows.
If the board isn’t already, switch it into Mass Storage mode, as shown at the image about.
Navigate to Computer, then Devices and Removable Storage. Open the removable disk drive corresponding to the LinkIt ONE development board.
Copy the three files we download from AWS IoT into the disk.
And in the code we had downloaded, there’s file named VeriSign-Class 3-Public-Primary-Certification-Authority-G5 (1).pem in \aws_mbedtls_mqtt\root_cert in, copy it to the Remove Disk as well, and rename it to root-CA.crt
Then put the switch to UART mode.
Step 7: Modify the Code
Click File>Sketchbook>aws_paho_shadow to open the code. There’s something need to be configured.
There are few thing need to be configured.
1. Find the code at aws_paho_shadow.h (image 1), remember that we had copied some code at step2? Copy the code and replace it in aws_paho_shadow.h
2. Configure your Wi-Fi AP (image2)
3. Run win+R, enter cmd, and ping the address of AWS_IOT_MQTT_HOST
You will get a series of number, it's an address. And modify IP_ADDRESS(line
40) to this line of number. (Here is 184.108.40.206)
Step 8: Hardware Connect
We will use Grove - Touch Sensor and Grove - LED Bar for example here.
- Base Shield put to 3V3
- Grove - Touch Sensor connect to D6
- Grove - LED Bar connect to D2
Step 9: Upload the Code
Connect your LinkIt ONE to PC, and remember insert the Wi-Fi alterna.
Open your Device Manage, you will find there’re 2 COM Ports.
Click Tools>Board and choose LinkIt ONE.
Click Tool>Ports and choost the number of MTK USB Debug Port.
Finally, click Upload button to Upload the code.
Then this step is completed.
Step 10: View Result
Change Arduino IDE Ports to MTK USB Moden Port, and open the Serial Monitor and set baud rate to 9600.
When you got ...X.509 certificazte... ok, it means the your device had connected to AWS successful. If there’s something wrong, please reset LinkIt ONE and try again.
Then let’s open AWS IoT website, sign in to your account. And click the thing you created minutes ago:
You will find a control panel on the right side.
You can check the status of Touch Sensor now. Try press the Touch Sensor, and update it.
You will find the status of Touch had changed.
Then let’s try to control the LED Bar.
Click Update shadow.
And replace the code with below code:
Then click Update shadow, your LED Bar will change to Level 5.
Put hand on AWS IoT Services Getting Started Guide to get more information AWS IoT.