|
| 1 | +--- |
| 2 | +title: Connect an STMicroelectronics B-L475E to Azure IoT Central quickstart |
| 3 | +description: Use Azure FreeRTOS device middleware to connect an STMicroelectronics B-L475E-IOT01A Discovery kit to Azure IoT and send telemetry. |
| 4 | +author: timlt |
| 5 | +ms.author: timlt |
| 6 | +ms.service: iot-develop |
| 7 | +ms.devlang: c |
| 8 | +ms.topic: quickstart |
| 9 | +ms.date: 01/27/2022 |
| 10 | +ms.custom: mode-other |
| 11 | +#Customer intent: As a device builder, I want to see a working IoT device sample connecting to Azure IoT, sending properties and telemetry, and responding to commands. As a solution builder, I want to use a tool to view the properties, commands, and telemetry an IoT Plug and Play device reports to the IoT hub it connects to. |
| 12 | +--- |
| 13 | + |
| 14 | +# Quickstart: Connect an STMicroelectronics B-L475E-IOT01A Discovery kit to Azure IoT Central |
| 15 | + |
| 16 | +**Applies to**: [Embedded device development](about-iot-develop.md#embedded-device-development)<br> |
| 17 | +**Total completion time**: 30 minutes |
| 18 | + |
| 19 | +In this quickstart, you use the Azure FreeRTOS middleware to connect the STMicroelectronics B-L475E-IOT01A Discovery kit (from now on, the STM DevKit) to Azure IoT Central. |
| 20 | + |
| 21 | +You complete the following tasks: |
| 22 | + |
| 23 | +* Install a set of embedded development tools to program an STM DevKit |
| 24 | +* Build an image and flash it onto the STM DevKit |
| 25 | +* Use Azure IoT Central to create cloud components, view properties, view device telemetry, and call direct commands |
| 26 | + |
| 27 | +## Prerequisites |
| 28 | + |
| 29 | +Operating system: Windows 10 or Windows 11 |
| 30 | + |
| 31 | +Hardware: |
| 32 | +- STM [B-L475E-IOT01A](https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html) devkit |
| 33 | +- USB 2.0 A male to Micro USB male cable |
| 34 | +- Wi-Fi 2.4 GHz |
| 35 | + |
| 36 | +## Prepare the development environment |
| 37 | + |
| 38 | +To set up your development environment, first you clone a GitHub repo that contains all the assets you need for the tutorial. Then you install a set of programming tools. |
| 39 | + |
| 40 | +### Clone the repo |
| 41 | + |
| 42 | +Clone the following repo to download all sample device code, setup scripts, and offline versions of the documentation. If you previously cloned this repo in another tutorial, you don't have to do it again. |
| 43 | + |
| 44 | +To clone the repo, run the following command: |
| 45 | + |
| 46 | +```shell |
| 47 | +git clone --recursive https://github.com/Azure-Samples/iot-middleware-freertos-samples |
| 48 | +``` |
| 49 | + |
| 50 | +### Install Ninja |
| 51 | + |
| 52 | +Ninja is a build tool that you use to build an image for the STM DevKit. |
| 53 | + |
| 54 | +1. Download [Ninja](https://github.com/ninja-build/ninja/releases) and unzip it to your local disk. |
| 55 | +1. Add the path to the Ninja executable to a PATH environment variable. |
| 56 | +1. Open a new console to recognize the update, and confirm that the Ninja binary is available in the `PATH` environment variable: |
| 57 | + ```shell |
| 58 | + ninja --version |
| 59 | + ``` |
| 60 | + |
| 61 | +### Install the tools |
| 62 | + |
| 63 | +The cloned repo contains a setup script that installs and configures the required tools. If you installed these tools in another tutorial in the getting started guide, you don't have to do it again. |
| 64 | +
|
| 65 | +> Note: The setup script installs the following tools: |
| 66 | +> * [CMake](https://cmake.org): Build |
| 67 | +> * [ARM GCC](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm): Compile |
| 68 | +> * [Termite](https://www.compuphase.com/software_termite.htm): Monitor serial port output for connected devices |
| 69 | +
|
| 70 | +To install the tools: |
| 71 | +
|
| 72 | +1. From File Explorer, navigate to the following path in the repo and run the setup script named *get-toolchain.bat*: |
| 73 | +
|
| 74 | + > *iot-middleware-freertos-samples\tools\get-toolchain.bat* |
| 75 | +
|
| 76 | +1. After the installation, open a new console window to recognize the configuration changes made by the setup script. Use this console to complete the remaining programming tasks in the tutorial. You can use Windows CMD, PowerShell, or Git Bash for Windows. |
| 77 | +1. Run the following code to confirm that CMake version **3.20** or later is installed. |
| 78 | +
|
| 79 | + ```shell |
| 80 | + cmake --version |
| 81 | + ``` |
| 82 | +
|
| 83 | +[!INCLUDE [iot-develop-embedded-create-central-app-with-device](../../includes/iot-develop-embedded-create-central-app-with-device.md)] |
| 84 | +
|
| 85 | +## Prepare the device |
| 86 | +To connect the STM DevKit to Azure, modify configuration settings, build the image, and flash the image to the device. |
| 87 | +
|
| 88 | +### Add configuration |
| 89 | +
|
| 90 | +1. Open the following file in a text editor: |
| 91 | +
|
| 92 | + *iot-middleware-freertos-samples/demos/projects/ST/b-l475e-iot01a/config/demo_config.h* |
| 93 | +
|
| 94 | +1. Set the Wi-Fi constants to the following values from your local environment. |
| 95 | +
|
| 96 | + |Constant name|Value| |
| 97 | + |-------------|-----| |
| 98 | + |`WIFI_SSID` |{*Your Wi-Fi ssid*}| |
| 99 | + |`WIFI_PASSWORD` |{*Your Wi-Fi password*}| |
| 100 | + |`WIFI_SECURITY_TYPE` |{*One of the enumerated Wi-Fi mode values in the file*}| |
| 101 | +
|
| 102 | +1. Set the Azure IoT device information constants to the values that you saved after you created Azure resources. |
| 103 | +
|
| 104 | + |Constant name|Value| |
| 105 | + |-------------|-----| |
| 106 | + |`democonfigID_SCOPE` |{*Your ID scope value*}| |
| 107 | + |`democonfigREGISTRATION_ID` |{*Your Device ID value*}| |
| 108 | + |`democonfigDEVICE_SYMMETRIC_KEY` |{*Your Primary key value*}| |
| 109 | +
|
| 110 | +1. Save and close the file. |
| 111 | +
|
| 112 | +### Build the image |
| 113 | +
|
| 114 | +1. In your console, run the following commands from the *iot-middleware-freertos-samples* directory to build the device image: |
| 115 | +
|
| 116 | + ```shell |
| 117 | + cmake -G Ninja -DVENDOR=ST -DBOARD=b-l475e-iot01a -Bb-l475e-iot01a . |
| 118 | + cmake --build b-l475e-iot01a |
| 119 | + ``` |
| 120 | +
|
| 121 | +2. After the build completes, confirm that the binary file was created in the following path: |
| 122 | +
|
| 123 | + *iot-middleware-freertos-samples\b-l475e-iot01a\demos\projects\ST\b-l475e-iot01a\iot-middleware-sample-gsg.bin* |
| 124 | +
|
| 125 | +### Flash the image |
| 126 | +
|
| 127 | +1. On the STM DevKit board, locate the **Reset** button (1), the Micro USB port (2), which is labeled **USB STLink**, and the board part number (3). You will refer to these items in the next steps. All of them are highlighted in the following picture: |
| 128 | +
|
| 129 | + :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/stm-devkit-board-475.png" alt-text="Locate key components on the STM DevKit board"::: |
| 130 | +
|
| 131 | +1. Connect the Micro USB cable to the **USB STLINK** port on the STM DevKit, and then connect it to your computer. |
| 132 | +
|
| 133 | + > [!NOTE] |
| 134 | + > For detailed setup information about the STM DevKit, see the instructions on the packaging, or see [B-L475E-IOT01A Resources](https://www.st.com/en/evaluation-tools/b-l475e-iot01a.html#resource) |
| 135 | +
|
| 136 | +1. In File Explorer, find the binary file named *iot-middleware-sample-gsg.bin* that you created previously. |
| 137 | +
|
| 138 | +1. In File Explorer, find the STM Devkit board that's connected to your computer. The device appears as a drive on your system with the drive label **DIS_L4IOT**. |
| 139 | + |
| 140 | +1. Paste the binary file into the root folder of the STM Devkit. The process to flash the board starts automatically and completes in a few seconds. |
| 141 | + |
| 142 | + > [!NOTE] |
| 143 | + > During the process, an LED toggles between red and green on the STM DevKit. |
| 144 | + |
| 145 | +### Confirm device connection details |
| 146 | + |
| 147 | +You can use the **Termite** app to monitor communication and confirm that your device is set up correctly. |
| 148 | + |
| 149 | +1. Start **Termite**. |
| 150 | + > [!TIP] |
| 151 | + > If you are unable to connect Termite to your devkit, install the [ST-LINK driver](https://www.st.com/en/development-tools/stsw-link009.html) and try again. See [Troubleshooting](troubleshoot-embedded-device-quickstarts.md) for additional steps. |
| 152 | +1. Select **Settings**. |
| 153 | +1. In the **Serial port settings** dialog, check the following settings and update if needed: |
| 154 | + * **Baud rate**: 115,200 |
| 155 | + * **Port**: The port that your STM DevKit is connected to. If there are multiple port options in the dropdown, you can find the correct port to use. Open Windows **Device Manager**, and view **Ports** to identify which port to use. |
| 156 | + |
| 157 | + :::image type="content" source="media/quickstart-devkit-stm-b-l475e/termite-settings.png" alt-text="Screenshot of serial port settings in the Termite app"::: |
| 158 | + |
| 159 | +1. Select OK. |
| 160 | +1. Press the **Reset** button on the device. The button is black and is labeled on the device. |
| 161 | +1. In the **Termite** app, check the output to confirm that the device is initialized and connected to Azure IoT. After some initial connection details, you should begin to see your board sensors sending telemetry to Azure IoT. |
| 162 | + |
| 163 | + ```output |
| 164 | + Successfully sent telemetry message |
| 165 | + [INFO] [MQTT] [receivePacket:885] Packet received. ReceivedBytes=2. |
| 166 | + [INFO] [MQTT] [handlePublishAcks:1161] Ack packet deserialized with result: MQTTSuccess. |
| 167 | + [INFO] [MQTT] [handlePublishAcks:1174] State record updated. New state=MQTTPublishDone. |
| 168 | + Puback received for packet id: 0x00000003 |
| 169 | + [INFO] [AzureIoTDemo] [ulCreateTelemetry:197] Telemetry message sent {"magnetometerX":-204,"magnetometerY":-215,"magnetometerZ":-875} |
| 170 | + |
| 171 | + Successfully sent telemetry message |
| 172 | + [INFO] [MQTT] [receivePacket:885] Packet received. ReceivedBytes=2. |
| 173 | + [INFO] [MQTT] [handlePublishAcks:1161] Ack packet deserialized with result: MQTTSuccess. |
| 174 | + [INFO] [MQTT] [handlePublishAcks:1174] State record updated. New state=MQTTPublishDone. |
| 175 | + Puback received for packet id: 0x00000004 |
| 176 | + [INFO] [AzureIoTDemo] [ulCreateTelemetry:197] Telemetry message sent {"accelerometerX":22,"accelerometerY":4,"accelerometerZ":1005} |
| 177 | + |
| 178 | + Successfully sent telemetry message |
| 179 | + [INFO] [MQTT] [receivePacket:885] Packet received. ReceivedBytes=2. |
| 180 | + [INFO] [MQTT] [handlePublishAcks:1161] Ack packet deserialized with result: MQTTSuccess. |
| 181 | + [INFO] [MQTT] [handlePublishAcks:1174] State record updated. New state=MQTTPublishDone. |
| 182 | + Puback received for packet id: 0x00000005 |
| 183 | + [INFO] [AzureIoTDemo] [ulCreateTelemetry:197] Telemetry message sent {"gyroscopeX":0,"gyroscopeY":-700,"gyroscopeZ":350} |
| 184 | + ``` |
| 185 | + |
| 186 | + > [!IMPORTANT] |
| 187 | + > If the DNS client initialization fails and notifies you that the Wi-Fi firmware is out of date, you'll need to update the Wi-Fi module firmware. Download and install the [Inventek ISM 43362 Wi-Fi module firmware update](https://www.st.com/resource/en/utilities/inventek_fw_updater.zip). Then press the **Reset** button on the device to recheck your connection, and continue with this quickstart. |
| 188 | +
|
| 189 | +Keep Termite open to monitor device output in the remaining steps. |
| 190 | +
|
| 191 | +## Verify the device status |
| 192 | +
|
| 193 | +To view the device status in the IoT Central portal: |
| 194 | +1. From the application dashboard, select **Devices** on the side navigation menu. |
| 195 | +1. Confirm that the **Device status** of the device is updated to **Provisioned**. |
| 196 | +1. Confirm that the **Device template** of the device has been updated to **STM L475 FreeRTOS Getting Started Guide.** |
| 197 | +
|
| 198 | + :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-device-view-status.png" alt-text="Screenshot of device status in IoT Central"::: |
| 199 | +
|
| 200 | +## View telemetry |
| 201 | +
|
| 202 | +In IoT Central, you can view the flow of telemetry from your device to the cloud. |
| 203 | +
|
| 204 | +To view telemetry in IoT Central: |
| 205 | +1. From the application dashboard, select **Devices** on the side navigation menu. |
| 206 | +1. Select the device from the device list. |
| 207 | +1. Select the **Overview** tab on the device page, and view the telemetry as the device sends messages to the cloud. |
| 208 | +
|
| 209 | + :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-device-telemetry.png" alt-text="Screenshot of device telemetry in IoT Central"::: |
| 210 | +
|
| 211 | +## Call a command on the device |
| 212 | +
|
| 213 | +You can also use IoT Central to call a command that you have implemented on your device. In this section, you call a method that enables you to turn an LED on or off. |
| 214 | +
|
| 215 | +To call a command in IoT Central portal: |
| 216 | +
|
| 217 | +1. Select the **Command** tab from the device page. |
| 218 | +1. Set the **State** dropdown value to *True*, and then select **Run**. The LED light should turn on. |
| 219 | +
|
| 220 | + :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-invoke-method.png" alt-text="Screenshot of calling a direct method on a device in IoT Central"::: |
| 221 | +
|
| 222 | +1. Set the **State** dropdown value to *False*, and then select **Run**. The LED light should turn off. |
| 223 | +
|
| 224 | +## View device information |
| 225 | +
|
| 226 | +You can view the device information from IoT Central. |
| 227 | +
|
| 228 | +Select **About** tab from the device page. |
| 229 | +
|
| 230 | +:::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-device-about.png" alt-text="Screenshot of device information in IoT Central"::: |
| 231 | +
|
| 232 | +## Troubleshoot and debug |
| 233 | +
|
| 234 | +If you experience issues when you build the device code, flash the device, or connect, see [Troubleshooting](troubleshoot-embedded-device-quickstarts.md). |
| 235 | +
|
| 236 | +To debug the application, see [Debugging with Visual Studio Code](https://github.com/azure-rtos/getting-started/blob/master/docs/debugging.md). |
| 237 | +
|
| 238 | +## Clean up resources |
| 239 | +
|
| 240 | +If you no longer need the Azure resources created in this tutorial, you can delete them from the IoT Central portal. Optionally, if you continue to another article in this Getting Started content, you can keep the resources you've already created and reuse them. |
| 241 | + |
| 242 | +To keep the Azure IoT Central sample application but remove only specific devices: |
| 243 | + |
| 244 | +1. Select the **Devices** tab for your application. |
| 245 | +1. Select the device from the device list. |
| 246 | +1. Select **Delete**. |
| 247 | + |
| 248 | +To remove the entire Azure IoT Central sample application and all its devices and resources: |
| 249 | + |
| 250 | +1. Select **Administration** > **Your application**. |
| 251 | +1. Select **Delete**. |
| 252 | + |
| 253 | +## Next Steps |
| 254 | + |
| 255 | +In this quickstart, you built a custom image that contains the Azure FreeRTOS middleware sample code. Then you flashed the image to the STM DevKit device. You also used the IoT Central portal to create Azure resources, connect the STM DevKit securely to Azure, view telemetry, and send messages. |
| 256 | + |
| 257 | +As a next step, explore the following articles to learn how to work with embedded devices and connect them to Azure IoT. |
| 258 | + |
| 259 | +> [!div class="nextstepaction"] |
| 260 | +> [Azure FreeRTOS middleware samples](https://github.com/Azure-Samples/iot-middleware-freertos-samples) |
| 261 | +> [!div class="nextstepaction"] |
| 262 | +> [Azure RTOS embedded development quickstarts](quickstart-devkit-mxchip-az3166.md) |
| 263 | +> [!div class="nextstepaction"] |
| 264 | +> [Azure IoT device development documentation](./index.yml) |
0 commit comments