Mbed OS example for AWS IoT Core
AWS Mbed OS example
The example project is part of the Arm Mbed OS Official Examples. It contains an application that connects to an AWS MQTT broker and publishes a message every 1 second for 10 seconds or until a message is received.
You can build the project with all supported Mbed OS build tools. However, this example project specifically refers to the command-line interface tool Arm Mbed CLI.
(Note: To see a rendered example you can import into the Arm Online Compiler, please see our import quick start.)
Summary of steps:
- Obtain the necessary keys and certificates to connect a device to AWS. This can be done in various ways after logging in to the AWS IoT console. You can refer to AWS documentation here. Follow the steps listed on AWS documentation to create an IoT policy for your device and attaching that policy to your device.
NOTE: If you have an admin for your AWS account, please contact them to add a user to the account. You should obtain your login credentials from your admin in this case.
- Once you have downloaded the credentials, you will need to place them in the
- Once you have created the “thing”, you will need to obtain the custom endpoint name from the console. At the time of writing this document, you can find it under “Settings” in the IoT console. In
aws-endpoint.valueto be that of the custom endpoint.
- If using WiFi, you will also need to enter your network’s SSID and password in
- You can then build the example and flash your target with the newly built binary using Arm Mbed CLI.
- On the AWS console, you will then need to subscribe and publish to the topic created. At the time of writing this document, you can find this under “Test” on the console.
- With the example running, you can monitor a serial terminal to see that the device connects to your network, exchanges some TLS handshakes, connects to AWS and publishes to the topic you just subscribed. This can be seen on the AWS console as incoming messages.
- You can also publish to this topic from the AWS console. This example demonstrates a string being appended as
"Hello <your string>!". You can “send” this from the AWS console and see the device responding with the
received + appendedstring on the serial terminal of your device.
Downloading this project
Clone this repository on your system, and change the current directory to where the project was cloned:
$ git clone firstname.lastname@example.org:armmbed/mbed-os-example-aws && cd mbed-os-example-aws $ mbed deploy
Alternatively, you can download the example project with Arm Mbed CLI using the
$ mbed import mbed-os-example-aws && cd mbed-os-example-aws
Building and running
- Configure the example using
mbed_app.jsonand add your credentials in
- Connect a USB cable between the USB port on the board and the host computer.
- Run the following command to build the example project, program the microcontroller flash memory, and open a serial terminal:
$ mbed compile -m detect -t <TOOLCHAIN> --flash --sterm
Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB.
The binary is located at
Depending on the target, you can build the example project with the
ARM toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:
$ mbed compile -S
The application connects to an AWS MQTT broker and publishes a message every second for 10 seconds or until a message is received.
On reception of a message, the application displays on the console the message prefixed with
If you have problems, you can review the documentation for suggestions on what could be wrong and how to fix it.
- Mbed OS Stats API.
- Mbed OS Configuration.
- Mbed OS Serial Communication.
- Mbed OS bare metal.
- Mbed boards.
- AWS IoT Core
- AWS IoT Core - Embedded C SDK
License and contributions
The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.