In this project, you will create an Azure IoT Hub, connect DevKit to it, and collect the temperature and humidity data from sensors and send the data to the IoT hub.

What you learn

  • How to create an IoT Hub and register a device for MXChip IoT DevKit.
  • How to collect sensor data by running a sample application on MXChip IoT DevKit.
  • How to send the sensor data to your IoT hub.

What you need

Finish the Getting Started Guide to:

  • Have your DevKit connected to Wi-Fi
  • Prepare the development environment

An active Azure subscription. If you do not have one, you can register via one of the methods:

Step 1. Open the project folder

A. Start VS Code

Make sure your DevKit is not connected. Start VS Code first and connect the DevKit to your computer. VS Code automatically finds the DevKit and opens an introduction page:

Introduction page

Notice: Occasionally, when you launch VS Code, you are prompted with error that cannot find Arduino IDE or related board package. Close VS Code, launch Arduino IDE once again, and VS Code should locate Arduino IDE path correctly.

B. Open the Arduino Examples folder

Expand left side ARDUINO EXAMPLES section, browse to Examples for MXCHIP AZ3166 > AzureIoT, and select GetStarted. This will open a new VS Code window with project folder in it.

Arduino Examples tab

If you happen to close the pane, you can reopen it. Use Ctrl+Shift+P (macOS: Cmd+Shift+P) to open the command palette, type Arduino, and then find and select Arduino: Examples.

Step 2. Provision Azure services

In the solution window, run your task through Ctrl+P (macOS: Cmd+P) by entering task cloud-provision:

In the VS Code terminal, an interactive command line guides you through provisioning the required Azure services:

Interactive command line

Notice: If the page hangs in the loading status when trying to sign in to Azure, plese check this FAQ steps to solve it.

Step 3. Build and upload Arduino sketch

Windows

  1. Use Ctrl+P to run task device-upload.
  2. The terminal prompts you to enter configuration mode. To do so, hold down button A, then push and release the reset button. The screen displays the DevKit id and ‘Configuration’.

This is to set the connection string that retrieves from task cloud-provision step.

Then VS Code starts verifying and uploading the Arduino sketch:

Verification and upload of the Arduino sketch

The DevKit reboots and starts running the code.

Notice: Occasionally, you get error “Error: AZ3166: Unknown package”. This is due to the board package index is not refreshed. Check this FAQ steps to solve it.

macOS

  1. Put DevKit into configuration mode: Hold down button A, then push and release the reset button. The screen displays ‘Configuration’.
  2. Use Cmd+P to run task device-upload.

This is to set the connection string that retrieves from task cloud-provision step.

Then VS Code starts verifying and uploading the Arduino sketch:

device-upload

The DevKit reboots and starts running the code.

Notice: Occasionally, you get error “Error: AZ3166: Unknown package”. This is due to the board package index is not refreshed. Check this FAQ steps to solve it.

Test the project

In VS Code, following these steps to open and set up the Serial Monitor:

  1. Click the COM[X] word on the status bar to set the right COM port with STMicroelectronics: com-port

  2. Click power plug icon on the status bar to open the Serial Monitor: serial-monitor

  3. On the status bar, click the number that represents the Baud Rate and set to 115200: baud-rate

The sample application is running successfully when you see the following results:

  • The Serial Monitor displays the same information as the content in the screenshot below.
  • The LED on MXChip IoT DevKit is blinking.

Final output in VS Code

Problems and feedback

If you encounter problems, you can find FAQs if you encounter problems or reach out to us from the channels below.

Next steps

You have successfully connected an MXChip IoT DevKit to your IoT hub, and you have sent the captured sensor data to your IoT hub.

To continue getting started with Azure IoT Hub and to explore other IoT scenarios, see:

Updated: