This directory contains sample applications for aws-iot-device-sdk-cpp-v2.
MQTT5 is the recommended MQTT Client. Additional information and usage instructions can be found in the MQTT5 User Guide. The samples below will create an MQTT5 client, connect using the selected method, subscribe to a topic, publish to the topic, and then disconnect.
| MQTT5 Client Sample | Description |
|---|---|
| X509-based mutual TLS | Demonstrates connecting to AWS IoT Core using X.509 certificates and private keys. |
| Websockets with Sigv4 authentication | Shows how to authenticate over websockets using AWS Signature Version 4 credentials. |
| AWS Signed Custom Authorizer Lambda Function | Connecting with a signed Lambda-backed custom authorizer. |
| AWS Unsigned Custom Authorizer Lambda Function | Connecting with an unsigned Lambda-backed custom authorizer. |
| PKCS11 | Demonstrates connecting using a hardware security module (HSM) or smartcard with PKCS#11. |
| Other Connection Methods | More connection methods are available for review in the MQTT5 Userguide |
AWS offers a number of IoT related services using MQTT. The samples below demonstrate how to use the service clients provided by the SDK to interact with those services.
| Service Client Sample | Description |
|---|---|
| Shadow | Manage and sync device state using the IoT Device Shadow service. |
| Jobs | Receive and execute remote operations sent from the Jobs service. |
| Basic Fleet Provisioning | Provision a device using the Fleet Provisioning template. |
| CSR Fleet Provisioning | Demonstrates CSR-based device certificate provisioning. |
| Commands | Receive and process remote instructions using AWS IoT Device Management commands |
Samples that interact with AWS Greengrass.
| Greengrass Sample | Description |
|---|---|
| Greengrass Discovery | Discover and connect to a local Greengrass core. |
| Greengrass IPC | Demonstrates Inter-Process Communication (IPC) with Greengrass components. |
| Sample | Description |
|---|---|
| Device Defender | Monitor the health of your IoT device using AWS IoT Device Defender. |
| Secure Tunneling | Connect a destination or a source Secure Tunnel Client to an AWS IoT Secure Tunnel endpoint. |
| Secure Tunneling Notification | Receive a tunnel notification using a Secure Tunnel Client. |
First build and install aws-iot-devices-sdk-cpp-v2 with following instructions from Installation.
Change directory into one of the samples. Under the directory of the sample you wish to build, run the following commands:
cmake -B build -S . -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DCMAKE_BUILD_TYPE="<Release|RelWithDebInfo|Debug>" .
cmake --build build --config "<Release|RelWithDebInfo|Debug>"For CMake versions that do not support the -B command, go to the directory of the sample you wish to build and run the following commands:
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DCMAKE_BUILD_TYPE="<Release|RelWithDebInfo|Debug>" ..
cmake --build . --config "<Release|RelWithDebInfo|Debug>"Change directory to the aws-iot-device-sdk-cpp-v2/samples directory and then run the following commands:
cmake -B build -S . -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DCMAKE_BUILD_TYPE="<Release|RelWithDebInfo|Debug>"
cmake --build build --config "<Release|RelWithDebInfo|Debug>"This will compile all of the samples at once. You can then find the samples in the aws-iot-device-sdk-cpp-v2/samples/build folder. For example, the MQTT5 X509 sample will be located at aws-iot-device-sdk-cpp-v2/samples/build/mqtt/mqtt5_x509.
For CMake versions that do not support the -B command, go to the aws-iot-device-sdk-cpp-v2/samples directory and run the following commands:
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>" -DCMAKE_BUILD_TYPE="<Release|RelWithDebInfo|Debug>" ..
cmake --build . --config "<Release|RelWithDebInfo|Debug>"Note that building all the samples at once is currently only available in the V2 C++ IoT SDK at this time.
-
-DCMAKE_PREFIX_PATHneeds to be set to the path aws-iot-device-sdk-cpp-v2 installed at. Since Installation takessdk-cpp-workspaceas an example, this file uses that example too. -
-DCMAKE_BUILD_TYPEand--configneeds to match theCMAKE_BUILD_TYPEwhen aws-iot-device-sdk-cpp-v2 built.--configis only REQUIRED for multi-configuration build tools.
All samples will show their options and arguments by passing in --help. For example:
./build/mqtt/mqtt5_x509/mqtt5_x509 --helpwill result in the following print output:
MQTT5 X509 Sample (mTLS)
options:
--help show this help message and exit
required arguments:
--endpoint IoT endpoint hostname
--cert Path to the certificate file to use during mTLS connection establishment
--key Path to the private key file to use during mTLS connection establishment
optional arguments:
--client_id Client ID (default: mqtt5-sample-<uuid>)
--topic Topic (default: test/topic)
--message Message payload (default: Hello from mqtt5 sample)
--count Messages to publish (0 = infinite) (default: 5)
The sample will not run without the required arguments and will notify you of missing arguments.
Instructions to enable logging are available in the FAQ under How do I enable logging.