AWS IoT

Learn how to use AWS IoT SDK with LinkIt Smart 7688 and Duo development boards.  AWS IoT is a managed cloud service on AWS cloud. 

You can use AWS IoT SDK to write programs running on LinkIt Smart 7688 and Duo development boards connected to the AWS IoT. It provides 3 different SDKs and their platform compatibility is shown below:

SDK bindingCompatible with
AWS IoT SDK for JavaScriptLinkIt Smart 7688, LinkIt Smart 7688 Duo
Arduino Yun SDKLinkIt Smart 7688 Duo only
Embedded CLinkIt Smart 7688, LinkIt Smart 7688 Duo. Requires a computer running OS X and Linux for cross compilation.

Environment setup

To run the SDK examples you'll need an AWS account and optionally AWS CLI (Command Line Interface).

  • Use an SD card for an additional storage space, see Mounting the root FS on an SD card. AWS CLI and SDK consume considerable amount of disk space.
  • Sign up for an AWS account
  • Install AWS CLI. You can install the CLI on LinkIt Smart 7688 development board directly with pip install awscli or use your PC to install it.
  • Generate certificates required by the examples according to instructions at AWS IoT SDK for JavaScript.
  • Copy the certificates, private key and root-CA files to LinkIt Smart 7688 development board under ~/certs directory. Follow the instructions here to copy the files.

AWS IoT SDK for JavaScript

Simply follow the NPM installation steps:

npm install aws-iot-device-sdk 

Note that there will be two missing optional dependencies utf-8-validate@1.2.1 and bufferutil@1.2.1 that can be ignored.

Make sure you have copied proper certification files to ~/certs directory before running the examples.

Then you should be able to run the examples from the SDK:

node examples/thing-example.js -f ~/certs --test-mode=1
node examples/thing-example.js -f ~/certs --test-mode=2

For additional examples and documentation, visit the GitHub repository for the AWS IoT SDK for JavaScript.

AWS IoT Arduino Yun SDK

AWS IoT Arduino Yun SDK is not compatible with LinkIt Smart 7688 development board. You'll need LinkIt Smart 7688 Duo development board to run this SDK.

  1. Enable the Yun bridge so that the LinkIt Smart 7688 Duo development board will act as a Yun device.
  2. Connect the board to the same network as your computer. Make sure it has access to the internet.
  3. Use your AWS IoT Console, click Connect a device to generate certification files, as shown below. Download and store the certification files to your computer.
  4. Copy the resulting configuration text, as shown below. 

  5. Download the root CA file and rename it to root-CA.crt.
  6. Follow the SDK instructions to extract the SDK files to your computer and install the libraries and examples in the Arduino IDE.
    • You need to place the certification files from Step 3 according to the instructions.
    • The instructions will ask you to fill [your_boards_ip], you can use mylinkit.local as the board address.
  7. Before you run the examples, you'll need to paste the code from Step 4 to the aws_iot_config.h in each example project.

AWS IoT Embedded-C SDK

Prerequisites

You'll need a computer running OS X or Ubuntu Linux. The setup requires cross compilation toolchain to use the AWS IoT embedded-C SDK.

Build and run an example application

To build an example application.

  1. Download and setup the cross-compilation tools (OpenWrt SDK) from 下載. Make sure you can successfully build and deploy a helloworld example application.
  2. Locate the path to the cross compilation toolchain. If you extract the OpenWrt SDK in path WRT_SDK, the toolchain is in

    WRT_SDK/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin  
  3. Download the AWS IoT Embedded-C SDK from source. There are two versions; in this example the mbedTLS from ARM version is used.
  4. Extract the downloaded AWS IoT SDK, under the path, such as AWS_SDK.
  5. Use your AWS IoT Console, click Connect a device to generate certification files. Download and store the certification files under AWS_SDK/certs directory.
  6. Navigate the the subscribe_publish_sample sample application directory:

    cd AWS_SDK/sample_apps/subscribe_publish_sample  
  7. Copy the resulting configuration text to aws_iot_config.h, it will look similar to this:

    // Get from console  
    // =================================================  
    #define AWS_IOT_MQTT_HOST              "A1XY4MZO1406ZZ.iot.us-west-2.amazonaws.com" 
    #define AWS_IOT_MQTT_PORT              8883  
    #define AWS_IOT_MQTT_CLIENT_ID         "linkit_device"  
    #define AWS_IOT_MY_THING_NAME          "linkit_device"  
    #define AWS_IOT_ROOT_CA_FILENAME       "root-CA.crt"  
    #define AWS_IOT_CERTIFICATE_FILENAME   "b77f46f13c-certificate.pem.crt"
    #define AWS_IOT_PRIVATE_KEY_FILENAME   "b77f46f13c-private.pem.key"  
    // =================================================
  8. Modify the Makefile of the sample application. Open the Makefile and find the following line at the beginning of the file:

    CC = gcc

    remove the line and modify it to use the cross compilation toolchain:

    export STAGING_DIR = WRT_SDK/staging_dir/  CROSS_COMPILE = WRT_SDK/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-uclibc-  
    export CC = $(CROSS_COMPILE)gcc  
    export AR = $(CROSS_COMPILE)ar  
    export LD = $(CROSS_COMPILE)ld  
    export RANLIB = $(CROSS_COMPILE)ranlib
    
  9. Type make to start building the sample application. It'll build an executable file subscribe_publish_sample.
  10. Make sure the board is connected to the internet and is in the same network as your computer. Copy the certification files and the sample application to the board:

    ssh root@mylinkit.local 'mkdir -p ~/aws_sdk/certs' 
    ssh root@mylinkit.local 'mkdir -p ~/aws_sdk/sample_apps/subscribe_publish_sample' 
    scp -r AWS_SDK/certs/* root@mylinkit.local:~/aws_sdk/certs  
    scp -r AWS_SDK/sample_apps/subscribe_publish_sample/subscribe_publish_sample root@mylinkit.local:~/aws_sdk/sample_apps/subscribe_publish_sample  
  11. Execute the sample application on the board. Sign into the console:

    ssh root@mylinkit.local

    Run the example: 

    cd ~/aws_sdk/sample_apps/subscribe_publish_sample  ./subscribe_publish_sample
  12. You should see the following log printed continuously:

    Subscribing...  
    -->sleep  
    -->sleep  
    Subscribe callback  sdkTest/sub    hello from SDK : 0  
    -->sleep  
    Subscribe callback  sdkTest/sub    hello from SDK : 1  
    -->sleep  
    Subscribe callback  sdkTest/sub    hello from SDK : 2  
    -->sleep  
    Subscribe callback  sdkTest/sub    hello from SDK : 3  
    -->sleep  
    Subscribe callback  sdkTest/sub    hello from SDK : 4  
    -->sleep  

    Type ctrl-c to stop the execution.

You can build other examples or your own applications a similar way. You need to modify the Makefile and aws_iot_config.h for each application as described in Step 7 and 8.