Skip to content

Commit 5ae025e

Browse files
authored
[PC-1467] - Getting started guide for AWS IoT Core (update) (#1484)
* Content update (Andrea's review) * Content update (minor fixes)
1 parent 9a63d8d commit 5ae025e

File tree

6 files changed

+84
-15
lines changed

6 files changed

+84
-15
lines changed
263 KB
Loading
337 KB
Loading
314 KB
Loading
237 KB
Loading
345 KB
Loading

content/hardware/07.opta/opta-family/opta/tutorials/getting-started-with-aws-iot-core/content.md

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,49 @@ hardware:
1919

2020
AWS IoT Core is a managed Cloud service that lets connected devices easily and securely interact with Cloud applications and other devices. AWS IoT Core can support billions of devices and trillions of messages and can process and route those messages to AWS endpoints and other devices reliably and securely. Devices can connect to AWS IoT Core using the following protocols: HTTP, WebSockets, and MQTT.
2121

22-
This tutorial will walk you through how to connect an Opta™ WiFi device securely to AWS IoT Core using the MQTT protocol. MQTT (Message Queuing Telemetry Transport) is a highly lightweight machine-to-machine (M2M) connectivity protocol that provides a messaging subscription and publish transport.
22+
In this tutorial, you will learn how to securely connect an Opta™ device to AWS IoT Core using the MQTT protocol. MQTT (Message Queuing Telemetry Transport) is a highly lightweight machine-to-machine (M2M) connectivity protocol that uses a publish/subscribe messaging model. It is particularly suitable for Internet of Things (IoT) applications due to its bandwidth efficiency and ability to ensure message delivery over unstable networks. By the end of this tutorial, you will have the necessary skills to set up your Opta™ device to publish data to the AWS IoT Core and receive data from it.
2323

2424
## Goals
2525

2626
- Learn how to connect an Opta™ device to the AWS IoT Core.
27+
- Learn how to generate a Certificate Signing Request (CSR) using the Arduino ecosystem tools.
2728

2829
## Hardware and Software Requirements
2930

3031
### Hardware Requirements
3132

32-
- [Opta™ WiFi](https://store.arduino.cc/collections/pro-family/products/opta-wifi) (x1)
33+
- [Opta™ WiFi Lite](https://store.arduino.cc/products/opta-lite), [Opta™ RS485](https://store.arduino.cc/products/opta-rs485) or [Opta™ WiFi](https://store.arduino.cc/collections/pro-family/products/opta-wifi) (x1)
3334
- [USB-C® cable](https://store.arduino.cc/products/usb-cable2in1-type-c) (x1)
3435

3536
### Software Requirements
3637

3738
- [Arduino IDE 1.8.10+](https://www.arduino.cc/en/software), [Arduino IDE 2](https://www.arduino.cc/en/software), or [Arduino Web Editor](https://create.arduino.cc/editor)
39+
- [NTPClient library](https://github.com/arduino-libraries/NTPClient)
40+
- [Arduino_JSON library](https://github.com/arduino-libraries/Arduino_JSON)
3841
- [ArduinoECCX08 library](https://github.com/arduino-libraries/ArduinoECCX08)
3942
- [ArduinoBearSSL library](https://github.com/arduino-libraries/ArduinoBearSSL)
4043
- [ArduinoMqttClient library](https://github.com/arduino-libraries/ArduinoMqttClient)
41-
- [Arduino Cloud Provider Examples](https://github.com/arduino/ArduinoCloudProviderExamples)
44+
- [Arduino_ConnectionHandler library](https://github.com/arduino-libraries/Arduino_ConnectionHandler)
45+
- [Arduino Cloud Provider Examples library](https://github.com/arduino/ArduinoCloudProviderExamples)
46+
47+
## AWS IoT Core
48+
49+
AWS IoT Core is at the heart of the AWS IoT suite of services, providing a centralized platform where IoT devices can connect to the Cloud. Its robust framework supports millions of devices and billions of messages, seamlessly and securely routing those messages between devices and various AWS Cloud services. Some key features of AWS IoT Core are the following:
50+
51+
- **Scalability**: AWS IoT Core is designed to scale IoT applications quickly, managing connections and messaging without manually provisioning infrastructure.
52+
- **Security**: A top priority with AWS IoT Core requiring devices to authenticate using X.509 certificates over TLS. This method ensures that the data exchanged between devices and the Cloud is encrypted and accessed only by authorized devices and services.
53+
- **Device gateway**: The device gateway enables devices to communicate efficiently and securely with AWS IoT Core. It supports real-time and persistent connections and is optimized to ensure low latency and high throughput.
54+
- **Message broker**: AWS IoT Core includes a message broker that handles messages to and from devices. It supports MQTT, a lightweight communication protocol ideal for IoT devices, including those with limited processing power or operating in environments with intermittent connectivity.
55+
- **Device shadows**: AWS IoT Core also offers device shadows, virtual representations of your devices in the Cloud. This allows for interaction with devices even when they are offline. You can retrieve the last reported state and set desired future states for the devices.
56+
- **Rule engine**: The AWS IoT Rules Engine processes and routes message data to other AWS services such as AWS Lambda, Amazon Kinesis, Amazon S3, and more. It can transform raw device data and control what data is stored, where, and how it's used.
57+
58+
### X.509 Certificates
59+
60+
X.509 certificates provide a robust layer of security for devices communicating with AWS IoT Core. When connecting using MQTT, these certificates are essential as they confirm the device's identity to AWS IoT Core, which is impossible with basic username and password authentication. This certificate-based system is part of the mutual authentication process, which is more secure than traditional credential-based methods.
61+
62+
With each device possessing a unique X.509 certificate, AWS IoT Core can ensure that the messages are secure and come from a trusted source. This method is fundamental in IoT ecosystems, where trust and identity verification are paramount to maintaining the system's integrity.
63+
64+
More information on X.509 certificate support on AWS IoT can be found [here](https://docs.aws.amazon.com/iot/latest/developerguide/x509-certs.html).
4265

4366
## Instructions
4467

@@ -48,27 +71,27 @@ This tutorial will need the latest version of the Arduino IDE; you can download
4871

4972
![Installing the Opta™ core in the Arduino IDE](assets/aws-iot_001.png)
5073

51-
This tutorial also requires the latest version of the `ArduinoECCX08`, `ArduinoBearSSL`, `ArduinoMqttClient`, and `Arduino Cloud Provider Examples` libraries installed on the Arduino IDE. You can do this by navigating to **Tools > Manage Libraries** or clicking the Library Manager icon in the left tab of the IDE. In the Library Manager tab, search for `ArduinoECCX08`, `ArduinoBearSSL`, `ArduinoMqttClient`, and `Arduino Cloud Provider Examples` and install the latest version.
74+
This tutorial also requires the latest version of the `NTPClient`, `Arduino_JSON `, `ArduinoECCX08`, `ArduinoBearSSL`, `ArduinoMqttClient`, `Arduino_ConnectionHandler` and `Arduino Cloud Provider Examples` libraries installed on the Arduino IDE. You can do this by navigating to **Tools > Manage Libraries** or clicking the Library Manager icon in the left tab of the IDE. In the Library Manager tab, search for `NTPClient`, `Arduino_JSON `, `ArduinoECCX08`, `ArduinoBearSSL`, `ArduinoMqttClient`, `Arduino_ConnectionHandler` and `Arduino Cloud Provider Examples` and install the latest version.
5275

5376
![Installing libraries in the Arduino IDE](assets/aws-iot_002.png)
5477

5578
### Setting Up Your AWS Account
5679

57-
If you do not have an existing AWS account and user, refer to the online AWS documentation at set up your AWS account. To get started, follow the steps outlined in the sections below:
80+
If you do not have an existing AWS account and user, refer to the online AWS documentation at [Set up your AWS account](https://docs.aws.amazon.com/iot/latest/developerguide/setting-up.html). To get started, follow the steps outlined in the sections below:
5881

5982
- [Sign up for an AWS account](https://docs.aws.amazon.com/iot/latest/developerguide/setting-up.html#aws-registration)
6083
- [Create an administrative user](https://docs.aws.amazon.com/iot/latest/developerguide/setting-up.html#create-an-admin)
6184
- [Open the AWS IoT console](https://docs.aws.amazon.com/iot/latest/developerguide/setting-up.html#iot-console-signin)
6285

6386
### Generating a Certificate Signing Request
6487

65-
As mentioned, AWS IoT Core requires devices that connect to it using the MQTT protocol to use X.509 certificates for authentication. We'll use an example sketch from the `ArduinoECCX08` library to generate a Certificate Signing Request (CSR) from an Opta™ WiFi device and then upload this CSR in the AWS console to create an X.509 certificate.
88+
As mentioned, AWS IoT Core requires devices that connect to it using the MQTT protocol to use X.509 certificates for authentication. We'll use an example sketch from the `ArduinoECCX08` library to generate a Certificate Signing Request (CSR) from an Opta™ device and then upload this CSR in the AWS console to create an X.509 certificate.
6689

67-
Open the `ECCX08CSR` example sketch by navigating to **File > Examples > ArduinoECCX08 > Tools**. To upload the code to your Opta™ WiFi device, click the **Verify** button to compile the sketch and check for errors; then click the **Upload** button to program the device with the sketch.
90+
Open the `ECCX08CSR` example sketch by navigating to **File > Examples > ArduinoECCX08 > Tools**. To upload the code to your Opta™ device, click the **Verify** button to compile the sketch and check for errors; then click the **Upload** button to program the device with the sketch.
6891

6992
![Verify and Upload buttons of the Arduino IDE](assets/aws-iot_003.png)
7093

71-
When finished, open the IDE's Serial Monitor. Ensure the line ending configuration is set to **Both NL & CR** as shown in the image below.
94+
When finished, open the IDE's Serial Monitor. Ensure the line ending configuration is set to **Both NL & CR**, as shown in the image below.
7295

7396
![Verify and Upload buttons of the Arduino IDE](assets/aws-iot_004.png)
7497

@@ -80,6 +103,16 @@ Now that we have a CSR to identify your Opta™ device, we need to login into th
80103

81104
### Creating Resources in AWS IoT Core
82105

106+
Refer to the online AWS documentation at [Create AWS IoT resources](https://docs.aws.amazon.com/iot/latest/developerguide/create-iot-resources.html). Follow the steps outlined in the following sections to provision resources for your device:
107+
108+
- [Create an AWS IoT policy](https://docs.aws.amazon.com/iot/latest/developerguide/create-iot-resources.html#create-iot-policy)
109+
- [Create a thing object](https://docs.aws.amazon.com/iot/latest/developerguide/create-iot-resources.html#create-aws-thing)
110+
111+
Pay special attention to the notes in the shared sections.
112+
113+
#### Opta™ Configuration as a Resource
114+
115+
83116
Login to your AWS account; in the Console Home search bar, search for the "IoT Core" service and select it.
84117

85118
![AWS Console Home](assets/aws-iot_006.png)
@@ -104,7 +137,7 @@ After selecting the Next Button, you will be transferred to a page where you can
104137

105138
![Device certificate page](assets/aws-iot_011.png)
106139

107-
In the image shown below, you can see an example policy created for testing purposes only. **Please do not use this policy in production since it is a wide-open policy and is not the best practice and standards**.
140+
In the image shown below, you can see an example policy created for testing purposes only. **Please do not use this policy in production since it is a wide-open policy and is not the best practice and standards**. Refer to the online AWS documentation at [Create an AWS IoT policy](https://docs.aws.amazon.com/iot/latest/developerguide/create-iot-resources.html#create-iot-policy).
108141

109142
![Example policy](assets/aws-iot_012.png)
110143

@@ -124,11 +157,11 @@ The first step to connect your Opta™ device is getting the **device data endpo
124157

125158
The next step depends on the variant of your Opta™ device you have.
126159

127-
- **For Opta™ Lite (SKU: AFX00003)**: Open the AWS IoT Wi-Fi sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta > **AWS_IoT_Opta_ethernet.ino**
160+
- **For Opta™ Lite (SKU: AFX00003)**: Open the AWS IoT Ethernet example sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta > **AWS_IoT_Opta_ethernet.ino**
128161

129-
- **For Opta™ Lite (SKU: AFX0001)**: Open the AWS IoT Wi-Fi sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta > **AWS_IoT_Opta_ethernet.ino**
162+
- **For Opta™ RS485 (SKU: AFX0001)**: Open the AWS IoT Ethernet example sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta > **AWS_IoT_Opta_ethernet.ino**
130163

131-
- **For Opta™ WiFi (SKU: AFX00002)**: If you connect using Ethernet, open the AWS IoT Wi-Fi® sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta >AWS_IoT_Opta_ethernet > **AWS_IoT_Opta_ethernet.ino**. If you connect using Wi-Fi®, open the AWS IoT Wi-Fi sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta->AWS_IoT_Opta_wifi > **AWS_IoT_Opta_wifi.ino**
164+
- **For Opta™ WiFi (SKU: AFX00002)**: If you connect using Ethernet, open the AWS IoT Ethernet example sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta >AWS_IoT_Opta_ethernet > **AWS_IoT_Opta_ethernet.ino**. If you connect using Wi-Fi®, open the AWS IoT Wi-Fi® example sketch in the Arduino IDE using the File > Examples > Arduino Cloud Provider Examples > AWSIoT > AWS_IoT_Opta->AWS_IoT_Opta_wifi > **AWS_IoT_Opta_wifi.ino**
132165

133166
In the `arduino_secrets.h` tab update the Wi-Fi® Setting with the SSID and password of your Wi-Fi® network. Update the `secret_broker` with the device data endpoint captured before, and update the `secret_port` with the proper port used to connect to AWS IoT. Finally, open the certificate file you downloaded with a text editor and copy/paste the value in the sketch in the `secret_certificate` area. In the image below, the `arduino_secrets.h` tab for the `AWS_IoT_Opta_wifi.ino` sketch is shown.
134167

@@ -144,17 +177,53 @@ Once the example sketch is set with proper values, the next step is to upload th
144177

145178
After modifying the example sketch, click the **Verify** button to compile the sketch and check for errors; then click the **Upload** button to program the device with the sketch. Open the IDE's Serial Monitor to monitor the connection Wi-Fi connection of your device and its connection to AWS.
146179

180+
![Monitoring the example sketch](assets/aws-iot_017.png)
181+
147182
The example sketch automatically connects to an Ethernet or a Wi-Fi® network and the AWS IoT Core broker. Then, it subscribes to the `arduino/incoming` topic and sends messages to the `arduino/outgoing` topic every five seconds.
148183

149184
### Testing the Example Sketch
150185

151-
As soon as your Opta™ device is connected to the AWS IoT broker, it publishes automatically a simple message to the `arduino/outgoing` topic every five seconds. On the AWS IoT Core console, open the **MQTT test client** and add a subscription for the `arduino/outgoing` topic; choose the JSON formatting as display option. See messages arriving from your Opta™ device every 5 seconds.
186+
As soon as your Opta™ device is connected to the AWS IoT broker, it publishes automatically a simple message to the `arduino/outgoing` topic every five seconds. On the AWS IoT Core console, open the **MQTT test client** and add a subscription for the `arduino/outgoing` topic; choose the JSON formatting as display option.
187+
188+
![MQTT test client in AWS](assets/aws-iot_019.png)
189+
190+
See messages arriving from your Opta™ device every five seconds.
191+
192+
![MQTT test client in AWS](assets/aws-iot_020.png)
152193

153-
On the AWS IoT Core console, open the MQTT test client and select the "Publish a Topic" tab. Add "arduino/incoming" as Topic name and click the "Publish" button to send data to Opta. Data in the "Message payload" text area shows on the Serial Monitor of the Arduino IDE.
194+
On the AWS IoT Core console, open the MQTT test client and select the "Publish to a topic" tab. Add `arduino/incoming` as Topic name and click the "Publish" button to send data to Opta™. Data in the "Message payload" text area shows on the Serial Monitor of the Arduino IDE.
195+
196+
![Receiving data in your Opta™ device](assets/aws-iot_021.png)
197+
198+
Please note the example sketch can parse only JSON messages in the form:
199+
200+
```json
201+
{
202+
"message": "Hello from AWS IoT console"
203+
}
204+
```
205+
206+
The message can be modified as you like, remember to adapt the example sketch accordingly.
154207

155208
## Troubleshooting
156209

157-
For more information, refer to the AWS online documentation on [Troubleshooting AWS IoT](https://docs.aws.amazon.com/iot/latest/developerguide/iot_troubleshooting.html).
210+
For more information with AWS, refer to the AWS online documentation on [Troubleshooting AWS IoT](https://docs.aws.amazon.com/iot/latest/developerguide/iot_troubleshooting.html). For more details on Opta™ devices, refer to Opta™'s online documentation on [Arduino Docs](https://docs.arduino.cc/hardware/opta).
211+
212+
If your Opta™ device fails to connect to AWS IoT Core, check the following:
213+
214+
- **X.509 certificate**: it must be activated in AWS IoT Core.
215+
216+
![Certificates area](assets/aws-iot_018.png)
217+
218+
- **Example sketch**: all the fields from the `arduino_secrets.h` file must be compiled (`SECRET_SSID`, `SECRET_PASS`, `SECRET_BROKER`, `SECRET_PORT`, and `SECRET_CERTIFICATE`).
219+
220+
![arduino_secrets.h file](assets/aws-iot_015.png)
221+
222+
223+
224+
225+
226+
158227

159228

160229

0 commit comments

Comments
 (0)