|
2 | 2 |
|
3 | 3 | # Mbed OS example for AWS cloud
|
4 | 4 |
|
5 |
| -The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/). 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. |
| 5 | +The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/). It contains two demos: |
| 6 | +* MQTT (default): publishes a message every 1 second for 10 messages or until a message is received. |
| 7 | +* Device Shadow service: retrieves a desired value from the cloud, then reports a string value and then an integer value to the cloud. |
6 | 8 |
|
7 | 9 | You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
|
8 | 10 | (Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
|
@@ -60,6 +62,8 @@ Starting with version 6.5, Mbed OS uses Mbed CLI 2. It uses Ninja as a build sys
|
60 | 62 |
|
61 | 63 | ## Building and running
|
62 | 64 |
|
| 65 | +### MQTT demo (default) |
| 66 | +
|
63 | 67 | 1. If using WiFi (e.g. on DISCO_L475VG_IOT01A), enter your network's SSID and password in [`mbed_app.json`](./mbed_app.json) (see [here](https://github.com/ARMmbed/mbed-os-example-wifi/blob/master/README.md#getting-started)). Keep any existing `\"`s. (If you use a different WiFi-enabled target, you may need to manually import its WiFi driver as described [here](https://github.com/ARMmbed/mbed-os-example-wifi#supported-hardware).)
|
64 | 68 |
|
65 | 69 | 1. For Ethernet (e.g on K64F), connect a cable to the port.
|
@@ -91,34 +95,62 @@ Depending on the target, you can build the example project with the `GCC_ARM` or
|
91 | 95 | $ mbed compile -S
|
92 | 96 | ```
|
93 | 97 |
|
| 98 | +### Device Shadow demo |
| 99 | +
|
| 100 | +Before running this demo, go to the AWS IoT Core console. In _Test_ -> _Subscribe to a topic_, subscribe to `$aws/things/<your thing>/shadow/#` (the `#` is a wildcard) on the AWS to monitor all Device Shadow updates. Then in _Publish to a topic_, publish to `$aws/things/<your thing>/shadow/update` the following payload: |
| 101 | +
|
| 102 | +```json |
| 103 | +{ |
| 104 | + "state": { |
| 105 | + "desired": { |
| 106 | + "DemoNumber": 200 |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +Build with the same steps as the MQTT demo, but also set `aws-client.shadow` to `true` in [`mbed_app.json`](./mbed_app.json) before compilation. |
| 113 | + |
94 | 114 | ## Expected output
|
95 | 115 |
|
| 116 | +### MQTT demo (default) |
| 117 | + |
96 | 118 | Once the example starts to run, you can [monitor a serial terminal](https://os.mbed.com/docs/mbed-os/v6.0/tutorials/serial-comm.html) 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.
|
97 | 119 |
|
98 | 120 | The application publishes a message every second for 10 seconds, or until it receives a message from the cloud:
|
99 | 121 | ```
|
100 |
| -[INFO][Main]: sending warning message: Warning: Only 10 second(s) left to say your name ! |
101 |
| -[INFO][Main]: sending warning message: Warning: Only 9 second(s) left to say your name ! |
102 |
| -[INFO][Main]: sending warning message: Warning: Only 8 second(s) left to say your name ! |
103 |
| -[INFO][Main]: sending warning message: Warning: Only 7 second(s) left to say your name ! |
| 122 | +[INFO][Main]: Publishing "10 messages left to send, or until we receive a reply" to topic <your topic> |
| 123 | +[INFO][Main]: Message sent successfully |
| 124 | +[INFO][Main]: Publishing "9 messages left to send, or until we receive a reply" to topic <your topic> |
| 125 | +[INFO][Main]: Message sent successfully |
| 126 | +[INFO][Main]: Publishing "8 messages left to send, or until we receive a reply" to topic <your topic> |
| 127 | +[INFO][Main]: Message sent successfully |
104 | 128 | ```
|
105 | 129 |
|
106 |
| -You can send a message to your device via the AWS IoT console (Test -> Publish to a topic). Use the same topic name you set in `aws-mqtt-topic.value` in [`mbed_app.json`](./mbed_app.json). |
| 130 | +You can send a message to your device via the AWS IoT Core console (_Test_ -> _Publish to a topic_). Use the same topic name you set in `aws-mqtt-topic.value` in [`mbed_app.json`](./mbed_app.json). Use the existing JSON structure and set "message" to one you want to send. |
107 | 131 |
|
108 |
| -On receipt of a message, the application displays on the console the message prefixed with `Hello␣`. |
| 132 | +On receipt of a message, the application displays on the console the message you sent via the AWS IoT Core console. |
| 133 | + |
| 134 | +### Device Shadow demo |
| 135 | + |
| 136 | +The following will be printed to the serial: |
| 137 | +``` |
| 138 | +[INFO][Main]: Device Shadow document downloaded |
| 139 | +[INFO][Main]: Desired value of DemoNumber: <value set on the AWS console> |
| 140 | +[INFO][Main]: Device Shadow reported string value published |
| 141 | +[INFO][Main]: Device Shadow reported integer value published |
| 142 | +``` |
109 | 143 |
|
110 | 144 | ## Troubleshooting
|
111 | 145 | If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
|
112 | 146 |
|
113 | 147 | ## Related Links
|
114 | 148 |
|
115 |
| -* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html). |
| 149 | +* [Mbed client for AWS IoT Core](https://github.com/ARMmbed/mbed-client-for-aws) |
| 150 | +* [AWS IoT Core](https://aws.amazon.com/iot-core/) |
116 | 151 | * [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html).
|
117 | 152 | * [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html).
|
118 |
| -* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html). |
119 | 153 | * [Mbed boards](https://os.mbed.com/platforms/).
|
120 |
| -* [AWS IoT Core](https://aws.amazon.com/iot-core/) |
121 |
| -* [AWS IoT Core - Embedded C SDK](https://github.com/aws/aws-iot-device-sdk-embedded-C/tree/v4_beta) |
122 | 154 |
|
123 | 155 | ### License and contributions
|
124 | 156 |
|
|
0 commit comments