This section helps you set up your ConnectCore device and create required resources to send, receive, and process messages from the AWS IoT platform.

The goal of this section is to have theawsiot-sampleapplication running in your device. This application monitors the CPU temperature and CPU load and allows you to remotely switch a device LED on and off.

Requirements

1. Program the AWS IoT image

Digi provides pre-built AWS IoT images.

1.1. Update from Linux

If your device is already running from Linux, use the update package (*.swu) to program the firmware:

1.2. Update from U-Boot

Alternatively, you can use U-Boot to program your device:

2. Register your device in the Thing Registry

Before connecting to AWS IoT, you must have your device in the Thing Registry. To do so, use theAWS IoT consoleor theAWS Command Line Interface (CLI)and follow the steps in theAWS IoT documentation.

When creating the AWS IoT Policy to attach to the Thing certificates, make sure you authorize your device to perform all the possible AWS IoT operations (connect, publish, receive, subscribe, get/update the shadow).

To do so, define the policy action as a*. Your policy must be similar to the following:

{"Version": "2012-10-17","Statement": [{“效应”:“允许”,"Action": "iot:*","Resource": "*"}]}

To learn more about AWS IoT policies, see theAWS IoT developer guide.

3. Install the certificates in the device file system

Your device must establish a secure connection with AWS IoT using X.509 certificates. You must generate these certificates and register them in your AWS account:

  1. To create and register the certificates, see theAWS IoT documentation.

  2. Install the certificate and private key associated with your device, for example inside the/etc/ssl/certsdirectory.

    $scp  root@:/etc/ssl/certs/$scp  root@:/etc/ssl/certs/$scp  root@:/etc/ssl/certs/$sync

4. Configure your device Thing

By default, theawsiot-sampleapplication reads the configuration to connect to AWS IoT platform from the/etc/awsiotsdk.conffile. Configure the following settings:

  1. thing_name:代表你的设备在你的名字WS IoT account.

  2. host: MQTT host or endpoint, similar toABCDEFG1234567.iot.us-west-2.amazonaws.com. You can obtain it from theSettingsmenu on the navigation bar of the AWS IoT Console.

  3. Certificates settings:

    1. certs_path: Absolute path of the certificates directory in the device. If you install them under/etc/ssl/certsyou do not need to modify it.

    2. rootca_filename: Name of the Root CA file located in the configuredcerts_path.

    3. signed_cert_filename: Name of the device signed certificate file located in the configuredcerts_path.

    4. private_key_filename: Name of the device private key file located in the configuredcerts_path.

Issue thesynccommand after editing the/etc/awsiotsdk.conffile.

5. Connect to AWS IoT

Once everything is properly configured, you can execute the demo application in the device:

#awsiot-sample

The device console displays information with every new update:

========================================= Updating shadow... Temperature variation greater than 1C Temperature: 44.512000C CPU Load: 0.000000% LED status: OFF =========================================

Follow these steps to control the LED:

  1. Log into yourAWS IoT Console.

  2. ClickTest.

  3. Enter#in theSubscription topictext field to subscribe to all topics.

  4. InPublish>Specify a topic to publish to, type$aws/things//shadow/update, whereis the thing name of your registered device.

  5. To switch on the LED, copy this in the text box:

    {"state" : {"desired" : {"ledON" : true}}}
  6. PressPublish to topicto send the message. The LED on the board switches on.

  7. To switch off the LED, change"ledON" : trueto"ledON" : falseand publish the message.

    {"state" : {"desired" : {"ledON" : false}}}