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
The AWS IoT prebuilt images.
An AWS IoT account. If you do not have one, create an AWS account athttps://aws.amazon.com/resources/create-account/.
A device connected to the Internet.
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:
Download the update package:
For ConnectCore 8M Nano Development Kit:
https://ftp1.digi.com/support/digiembeddedyocto/3.2/r3/images/ccimx8mn-dvk/fb/dey-image-aws-swu-ccimx8mn-dvk.swu
.
Follow the steps atProgram firmware from Linux.
1.2. Update from U-Boot
Alternatively, you can use U-Boot to program your device:
Download the images for each partition:
For ConnectCore 8M Nano Development Kit: from
https://ftp1.digi.com/support/digiembeddedyocto/3.2/r3/images/ccimx8mn-dvk/fb/
.
Follow the steps atProgram firmware from U-Boot.
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:
To create and register the certificates, see theAWS IoT documentation.
Install the certificate and private key associated with your device, for example inside the
/etc/ssl/certs
directory.$scp
root@ :/etc/ssl/certs/$scp root@ :/etc/ssl/certs/$scp root@ :/etc/ssl/certs/$sync
is the Verisign root CA server certificate used to authenticate the AWS IoT server. You can download it fromhttps://www.websecurity.digicert.com/content/dam/websitesecurity/digitalassets/desktop/pdfs/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem.
is the certificate attached to your Thing.
is the Thing’s private key.
is your device IP.
4. Configure your device Thing
By default, theawsiot-sampleapplication reads the configuration to connect to AWS IoT platform from the/etc/awsiotsdk.conf
file. Configure the following settings:
thing_name
:代表你的设备在你的名字WS IoT account.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.Certificates settings:
certs_path
: Absolute path of the certificates directory in the device. If you install them under/etc/ssl/certs
you do not need to modify it.rootca_filename
: Name of the Root CA file located in the configuredcerts_path
.signed_cert_filename
: Name of the device signed certificate file located in the configuredcerts_path
.private_key_filename
: Name of the device private key file located in the configuredcerts_path
.
Issue thesync command after editing the/etc/awsiotsdk.conf file. |
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:
Log into yourAWS IoT Console.
ClickTest.
Enter
#
in theSubscription topictext field to subscribe to all topics.InPublish>Specify a topic to publish to, type
$aws/things/
, where/shadow/update
is the thing name of your registered device.To switch on the LED, copy this in the text box:
{"state" : {"desired" : {"ledON" : true}}}
PressPublish to topicto send the message. The LED on the board switches on.
To switch off the LED, change
"ledON" : true
to"ledON" : false
and publish the message.{"state" : {"desired" : {"ledON" : false}}}