Tutorial: Connect a sample IoT Plug and Play device application running on Linux or Windows to IoT Hub

This tutorial shows you how to build a sample IoT Plug and Play device application, connect it to your IoT hub, and use the Azure IoT explorer tool to view the telemetry it sends. The sample application is written in C and is included in the Azure IoT device SDK for C. A solution builder can use the Azure IoT explorer tool to understand the capabilities of an IoT Plug and Play device without the need to view any device code.

Browse code

Prerequisites

Before you continue, make sure you've set up your environment, including your IoT hub.

You can run this tutorial on Linux or Windows. The shell commands in this tutorial follow the Linux convention for path separators '/', if you're following along on Windows be sure to swap these separators for '\'.

The prerequisites differ by operating system:

Linux

This tutorial assumes you're using Ubuntu Linux. The steps in this tutorial were tested using Ubuntu 18.04.

To complete this tutorial on Linux, install the following software on your local Linux environment:

Install GCC, Git, cmake, and all the required dependencies using the apt-get command:

sudo apt-get update
sudo apt-get install -y git cmake build-essential curl libcurl4-openssl-dev libssl-dev uuid-dev

Verify the version of cmake is above 2.8.12 and the version of GCC is above 4.4.7.

cmake --version
gcc --version

Windows

To complete this tutorial on Windows, install the following software in your local Windows environment:

Download the code

In this tutorial, you prepare a development environment you can use to clone and build the Azure IoT Hub Device C SDK.

Open a command prompt in the directory of your choice. Execute the following command to clone the Azure IoT C SDKs and Libraries GitHub repository into this location:

git clone https://github.com/Azure/azure-iot-sdk-c.git
cd azure-iot-sdk-c
git submodule update --init

Expect this operation to take several minutes to complete.

Build the code

You can build and run the code using Visual Studio or cmake at the command line.

Use Visual Studio

  1. Open the root folder of the cloned repository. After a couple of seconds, the CMake support in Visual Studio creates all you need to run and debug the project.

  2. When Visual Studio is ready, in Solution Explorer, navigate to the sample iothub_client/samples/pnp/pnp_simple_thermostat/.

  3. Right-click on the pnp_simple_thermostat.c file and select Add Debug Configuration. Select Default.

  4. Visual Studio opens the launch.vs.json file. Edit this file as shown in the following snippet to set the required environment variables. You made a note of the scope ID and enrollment primary key when you completed Set up your environment for the IoT Plug and Play quickstarts and tutorials:

    {
      "version": "0.2.1",
      "defaults": {},
      "configurations": [
        {
          "type": "default",
          "project": "iothub_client\\samples\\pnp\\pnp_simple_thermostat\\pnp_pnp_simple_thermostat.c",
          "projectTarget": "",
          "name": "pnp_simple_thermostat.c",
          "env": {
            "IOTHUB_DEVICE_SECURITY_TYPE": "DPS",
            "IOTHUB_DEVICE_DPS_ID_SCOPE": "<Your ID scope>",
            "IOTHUB_DEVICE_DPS_DEVICE_ID": "my-pnp-device",
            "IOTHUB_DEVICE_DPS_DEVICE_KEY": "<Your enrollment primary key>"
          }
        }
      ]
    }
    
  5. Right-click on the pnp_simple_thermostat.c file and select Set as Startup Item.

  6. To trace the code execution in Visual Studio, add a breakpoint to the main function in the pnp_simple_thermostat.c file.

  7. You can now run and debug the sample from the Debug menu.

The device is now ready to receive commands and property updates, and has started sending telemetry data to the hub. Keep the sample running as you complete the next steps.

Use cmake to build the code

You use the cmake command-line utility to build the code:

  1. Create a cmake subdirectory in the root folder of the device SDK, and navigate to that folder:

    cd azure-iot-sdk-c
    mkdir cmake
    cd cmake
    
  2. Run the following commands to build the SDK and samples:

    cmake -Duse_prov_client=ON -Dhsm_type_symm_key=ON -Drun_e2e_tests=OFF ..
    cmake --build .
    

Run the device sample

In Set up your environment, you created four environment variables to configure the sample to use the Device Provisioning Service (DPS) to connect to your IoT hub:

  • IOTHUB_DEVICE_SECURITY_TYPE with the value DPS
  • IOTHUB_DEVICE_DPS_ID_SCOPE with the DPS ID scope.
  • IOTHUB_DEVICE_DPS_DEVICE_ID with the value my-pnp-device.
  • IOTHUB_DEVICE_DPS_DEVICE_KEY with the enrollment primary key.
  • IOTHUB_DEVICE_DPS_ENDPOINT with the value global.azure-devices-provisioning.net.

To learn more about the sample configuration, see the sample readme.

To run the sample application in the SDK that simulates an IoT Plug and Play device sending telemetry to your IoT hub:

From the cmake folder, navigate to the folder that contains the executable file and run it:

# Bash
cd iothub_client/samples/pnp/pnp_simple_thermostat/
./pnp_simple_thermostat
REM Windows
cd iothub_client\samples\pnp\pnp_simple_thermostat\Debug
.\pnp_simple_thermostat.exe

Tip

To trace the code execution in Visual Studio on Windows, add a break point to the main function in the pnp_simple_thermostat.c file.

The device is now ready to receive commands and property updates, and has started sending telemetry data to the hub. Keep the sample running as you complete the next steps.

Use Azure IoT explorer to validate the code

After the device client sample starts, use the Azure IoT explorer tool to verify it's working.

  1. Open Azure IoT explorer.

  2. On the IoT hubs page, if you haven't already added a connection to your IoT hub, select + Add connection. Enter the connection string for the IoT hub you created previously and select Save.

  3. On the IoT Plug and Play Settings page, select + Add > Local folder and select the local models folder where you saved your model files.

  4. On the IoT hubs page, click on the name of the hub you want to work with. You see a list of devices registered to the IoT hub.

  5. Click on the Device ID of the device you created previously.

  6. The menu on the left shows the different types of information available for the device.

  7. Select IoT Plug and Play components to view the model information for your device.

  8. You can view the different components of the device. The default component and any extra ones. Select a component to work with.

  9. Select the Telemetry page and then select Start to view the telemetry data the device is sending for this component.

  10. Select the Properties (read-only) page to view the read-only properties reported for this component.

  11. Select the Properties (writable) page to view the writable properties you can update for this component.

  12. Select a property by it's name, enter a new value for it, and select Update desired value.

  13. To see the new value show up select the Refresh button.

  14. Select the Commands page to view all the commands for this component.

  15. Select the command you want to test set the parameter if any. Select Send command to call the command on the device. You can see your device respond to the command in the command prompt window where the sample code is running.

Review the code

This sample implements a simple IoT Plug and Play thermostat device. The thermostat model doesn't use IoT Plug and Play components. The DTDL model file for the thermostat device defines the telemetry, properties, and commands the device implements.

The device code uses the standard function to connect to your IoT hub:

deviceHandle = IoTHubDeviceClient_CreateFromConnectionString(connectionString, MQTT_Protocol)

The device sends the model ID of the DTDL model it implements in the connection request. A device that sends a model ID is an IoT Plug and Play device:

static const char g_ModelId[] = "dtmi:com:example:Thermostat;1";

...

IoTHubDeviceClient_SetOption(deviceHandle, OPTION_MODEL_ID, modelId)

The code that updates properties, handles commands, and sends telemetry is identical to the code for a device that doesn't use the IoT Plug and Play conventions.

The code uses the Parson library to parse JSON objects in the payloads sent from your IoT hub:

// JSON parser
#include "parson.h"

Clean up resources

If you've finished with the quickstarts and tutorials, see Clean up resources.

This tutorial shows you how to build a sample IoT Plug and Play device application, connect it to your IoT hub, and use the Azure IoT explorer tool to view the telemetry it sends. The sample application is written in C# and is included in the Azure IoT SDK for C#. A solution builder can use the Azure IoT explorer tool to understand the capabilities of an IoT Plug and Play device without the need to view any device code.

Browse code

Prerequisites

Before you continue, make sure you've set up your environment, including your IoT hub.

You can run this tutorial on Linux or Windows. The shell commands in this tutorial follow the Linux convention for path separators '/', if you're following along on Windows be sure to swap these separators for '\'.

Download the code

In this tutorial, you prepare a development environment you can use to clone and build the Azure IoT SDK for C# repository.

Open a command prompt in a folder of your choice. Run the following command to clone the Microsoft Azure IoT SDK for C# (.NET) GitHub repository into this location:

git clone  https://github.com/Azure/azure-iot-sdk-csharp

Build the code

You can now build the sample and run it. Run the following commands to build the sample:

cd azure-iot-sdk-csharp/iothub/device/samples/solutions/PnpDeviceSamples/Thermostat
dotnet build

Run the device sample

To run the sample, run the following command:

dotnet run

The device is now ready to receive commands and property updates, and has started sending telemetry data to the hub. Keep the sample running as you complete the next steps.

Use Azure IoT explorer to validate the code

After the device client sample starts, use the Azure IoT explorer tool to verify it's working.

  1. Open Azure IoT explorer.

  2. On the IoT hubs page, if you haven't already added a connection to your IoT hub, select + Add connection. Enter the connection string for the IoT hub you created previously and select Save.

  3. On the IoT Plug and Play Settings page, select + Add > Local folder and select the local models folder where you saved your model files.

  4. On the IoT hubs page, click on the name of the hub you want to work with. You see a list of devices registered to the IoT hub.

  5. Click on the Device ID of the device you created previously.

  6. The menu on the left shows the different types of information available for the device.

  7. Select IoT Plug and Play components to view the model information for your device.

  8. You can view the different components of the device. The default component and any extra ones. Select a component to work with.

  9. Select the Telemetry page and then select Start to view the telemetry data the device is sending for this component.

  10. Select the Properties (read-only) page to view the read-only properties reported for this component.

  11. Select the Properties (writable) page to view the writable properties you can update for this component.

  12. Select a property by it's name, enter a new value for it, and select Update desired value.

  13. To see the new value show up select the Refresh button.

  14. Select the Commands page to view all the commands for this component.

  15. Select the command you want to test set the parameter if any. Select Send command to call the command on the device. You can see your device respond to the command in the command prompt window where the sample code is running.

Review the code

This sample implements a simple IoT Plug and Play thermostat device. The model this sample implements doesn't use IoT Plug and Play components. The Digital Twins definition language (DTDL) model file for the thermostat device defines the telemetry, properties, and commands the device implements.

The device code connects to your IoT hub using the standard CreateFromConnectionString method. The device sends the model ID of the DTDL model it implements in the connection request. A device that sends a model ID is an IoT Plug and Play device:

private static void InitializeDeviceClientAsync()
{
  var options = new ClientOptions
  {
    ModelId = ModelId,
  };
  s_deviceClient = DeviceClient.CreateFromConnectionString(s_deviceConnectionString, TransportType.Mqtt, options);
  s_deviceClient.SetConnectionStatusChangesHandler((status, reason) =>
  {
     s_logger.LogDebug($"Connection status change registered - status={status}, reason={reason}.");
  });
}

The model ID is stored in the code as shown in the following snippet:

private const string ModelId = "dtmi:com:example:Thermostat;1";

The code that updates properties, handles commands, and sends telemetry is identical to the code for a device that doesn't use the IoT Plug and Play conventions.

The sample uses a JSON library to parse JSON objects in the payloads sent from your IoT hub:

using Newtonsoft.Json;

...

DateTime since = JsonConvert.DeserializeObject<DateTime>(request.DataAsJson);

Clean up resources

If you've finished with the quickstarts and tutorials, see Clean up resources.

This tutorial shows you how to build a sample IoT Plug and Play device application, connect it to your IoT hub, and use the Azure IoT explorer tool to view the telemetry it sends. The sample application is written in Java and is included in the Azure IoT device SDK for Java. A solution builder can use the Azure IoT explorer tool to understand the capabilities of an IoT Plug and Play device without the need to view any device code.

Browse code

Prerequisites

Before you continue, make sure you've set up your environment, including your IoT hub.

You can run this tutorial on Linux or Windows. The shell commands in this tutorial follow the Linux convention for path separators '/', if you're following along on Windows be sure to swap these separators for '\'.

To complete this tutorial, install the following software in your local development environment:

Download the code

In this tutorial, you prepare a development environment you can use to clone and build the Azure IoT Hub Device Java SDK.

Open a command prompt in the directory of your choice. Execute the following command to clone the Azure IoT Java SDKs and Libraries GitHub repository into this location:

git clone https://github.com/Azure/azure-iot-sdk-java.git

Build the code

Navigate to the root folder of the thermostat sample in the cloned Java SDK repository and build it:

cd azure-iot-sdk-java/device/iot-device-samples/pnp-device-sample/thermostat-device-sample
mvn clean package

Run the device sample

In Set up your environment, you created four environment variables to configure the sample to use the Device Provisioning Service (DPS) to connect to your IoT hub:

  • IOTHUB_DEVICE_SECURITY_TYPE with the value DPS
  • IOTHUB_DEVICE_DPS_ID_SCOPE with the DPS ID scope.
  • IOTHUB_DEVICE_DPS_DEVICE_ID with the value my-pnp-device.
  • IOTHUB_DEVICE_DPS_DEVICE_KEY with the enrollment primary key.
  • IOTHUB_DEVICE_DPS_ENDPOINT with the value global.azure-devices-provisioning.net.

To learn more about the sample configuration, see the sample readme.

From the /device/iot-device-samples/pnp-device-sample/thermostat-device-sample folder, run the application:

mvn exec:java -Dexec.mainClass="samples.com.microsoft.azure.sdk.iot.device.Thermostat"

The device is now ready to receive commands and property updates, and has started sending telemetry data to the hub. Keep the sample running as you complete the next steps.

Use Azure IoT explorer to validate the code

After the device client sample starts, use the Azure IoT explorer tool to verify it's working.

  1. Open Azure IoT explorer.

  2. On the IoT hubs page, if you haven't already added a connection to your IoT hub, select + Add connection. Enter the connection string for the IoT hub you created previously and select Save.

  3. On the IoT Plug and Play Settings page, select + Add > Local folder and select the local models folder where you saved your model files.

  4. On the IoT hubs page, click on the name of the hub you want to work with. You see a list of devices registered to the IoT hub.

  5. Click on the Device ID of the device you created previously.

  6. The menu on the left shows the different types of information available for the device.

  7. Select IoT Plug and Play components to view the model information for your device.

  8. You can view the different components of the device. The default component and any extra ones. Select a component to work with.

  9. Select the Telemetry page and then select Start to view the telemetry data the device is sending for this component.

  10. Select the Properties (read-only) page to view the read-only properties reported for this component.

  11. Select the Properties (writable) page to view the writable properties you can update for this component.

  12. Select a property by it's name, enter a new value for it, and select Update desired value.

  13. To see the new value show up select the Refresh button.

  14. Select the Commands page to view all the commands for this component.

  15. Select the command you want to test set the parameter if any. Select Send command to call the command on the device. You can see your device respond to the command in the command prompt window where the sample code is running.

Review the code

This sample implements a simple IoT Plug and Play thermostat device. The model this sample implements doesn't use IoT Plug and Play components. The DTDL model file for the thermostat device defines the telemetry, properties, and commands the device implements.

The device code uses the standard DeviceClient class to connect to your IoT hub. The device sends the model ID of the DTDL model it implements in the connection request. A device that sends a model ID is an IoT Plug and Play device:

private static void initializeDeviceClient() throws URISyntaxException, IOException {
    ClientOptions options = new ClientOptions();
    options.setModelId(MODEL_ID);
    deviceClient = new DeviceClient(deviceConnectionString, protocol, options);

    deviceClient.registerConnectionStatusChangeCallback((status, statusChangeReason, throwable, callbackContext) -> {
        log.debug("Connection status change registered: status={}, reason={}", status, statusChangeReason);

        if (throwable != null) {
            log.debug("The connection status change was caused by the following Throwable: {}", throwable.getMessage());
            throwable.printStackTrace();
        }
    }, deviceClient);

    deviceClient.open();
}

The model ID is stored in the code as shown in the following snippet:

private static final String MODEL_ID = "dtmi:com:example:Thermostat;1";

The code that updates properties, handles commands, and sends telemetry is identical to the code for a device that doesn't use the IoT Plug and Play conventions.

The sample uses a JSON library to parse JSON objects in the payloads sent from your IoT hub:

import com.google.gson.Gson;

...

Date since = new Gson().fromJson(jsonRequest, Date.class);

Clean up resources

If you've finished with the quickstarts and tutorials, see Clean up resources.

This tutorial shows you how to build a sample IoT Plug and Play device application, connect it to your IoT hub, and use the Azure IoT explorer tool to view the telemetry it sends. The sample application is written in Node.js and is included in the Azure IoT device SDK for Node.js. A solution builder can use the Azure IoT explorer tool to understand the capabilities of an IoT Plug and Play device without the need to view any device code.

Browse code

Prerequisites

Before you continue, make sure you've set up your environment, including your IoT hub.

You can run this tutorial on Linux or Windows. The shell commands in this tutorial follow the Linux convention for path separators '/', if you're following along on Windows be sure to swap these separators for '\'.

To complete this tutorial, you need Node.js on your development machine. You can download the latest recommended version for multiple platforms from nodejs.org.

You can verify the current version of Node.js on your development machine using the following command:

node --version

Download the code

In this tutorial, you prepare a development environment you can use to clone and build the Azure IoT Hub Device SDK for Node.js.

Open a command prompt in the directory of your choice. Execute the following command to clone the Microsoft Azure IoT SDK for Node.js GitHub repository into this location:

git clone https://github.com/Azure/azure-iot-sdk-node

Install required libraries

You use the device SDK to build the included sample code. The application you build simulates a device that connects to an IoT hub. The application sends telemetry and properties and receives commands.

  1. In a local terminal window, go to the folder of your cloned repository and navigate to the /azure-iot-sdk-node/device/samples/javascript folder. Then run the following command to install the required libraries:

    npm install
    

Run the sample device

This sample implements a simple IoT Plug and Play thermostat device. The model this sample implements doesn't use IoT Plug and Play components. The DTDL model file for the thermostat device defines the telemetry, properties, and commands the device implements.

Open the pnp_simple_thermostat.js file. In this file, you can see how to:

  1. Import the required interfaces.
  2. Write a property update handler and a command handler.
  3. Handle desired property patches and send telemetry.
  4. Optionally, provision your device using the Azure Device Provisioning Service (DPS).

In the main function, you can see how it all comes together:

  1. Create the device from your connection string or provision it using DPS.)
  2. Use the modelID option to specify the IoT Plug and Play device model.
  3. Enable the command handler.
  4. Send telemetry from the device to your hub.
  5. Get the devices twin and update the reported properties.
  6. Enable the desired property update handler.

In Set up your environment, you created four environment variables to configure the sample to use the Device Provisioning Service (DPS) to connect to your IoT hub:

  • IOTHUB_DEVICE_SECURITY_TYPE with the value DPS
  • IOTHUB_DEVICE_DPS_ID_SCOPE with the DPS ID scope.
  • IOTHUB_DEVICE_DPS_DEVICE_ID with the value my-pnp-device.
  • IOTHUB_DEVICE_DPS_DEVICE_KEY with the enrollment primary key.
  • IOTHUB_DEVICE_DPS_ENDPOINT with the value global.azure-devices-provisioning.net.

To learn more about the sample configuration, see the sample readme.

Run the sample application to simulate an IoT Plug and Play device that sends telemetry to your IoT hub. To run the sample application, use the following command:

node pnp_simple_thermostat.js

You see the following output, indicating the device has begun sending telemetry data to the hub, and is now ready to receive commands and property updates.

Device confirmation messages

Keep the sample running as you complete the next steps.

Use Azure IoT explorer to validate the code

After the device client sample starts, use the Azure IoT explorer tool to verify it's working.

  1. Open Azure IoT explorer.

  2. On the IoT hubs page, if you haven't already added a connection to your IoT hub, select + Add connection. Enter the connection string for the IoT hub you created previously and select Save.

  3. On the IoT Plug and Play Settings page, select + Add > Local folder and select the local models folder where you saved your model files.

  4. On the IoT hubs page, click on the name of the hub you want to work with. You see a list of devices registered to the IoT hub.

  5. Click on the Device ID of the device you created previously.

  6. The menu on the left shows the different types of information available for the device.

  7. Select IoT Plug and Play components to view the model information for your device.

  8. You can view the different components of the device. The default component and any extra ones. Select a component to work with.

  9. Select the Telemetry page and then select Start to view the telemetry data the device is sending for this component.

  10. Select the Properties (read-only) page to view the read-only properties reported for this component.

  11. Select the Properties (writable) page to view the writable properties you can update for this component.

  12. Select a property by it's name, enter a new value for it, and select Update desired value.

  13. To see the new value show up select the Refresh button.

  14. Select the Commands page to view all the commands for this component.

  15. Select the command you want to test set the parameter if any. Select Send command to call the command on the device. You can see your device respond to the command in the command prompt window where the sample code is running.

Clean up resources

If you've finished with the quickstarts and tutorials, see Clean up resources.

This tutorial shows you how to build a sample IoT Plug and Play device application, connect it to your IoT hub, and use the Azure IoT explorer tool to view the telemetry it sends. The sample application is written for Python and is included in the Azure IoT Hub Device SDK for Python. A solution builder can use the Azure IoT explorer tool to understand the capabilities of an IoT Plug and Play device without the need to view any device code.

Browse code

Prerequisites

Before you continue, make sure you've set up your environment, including your IoT hub.

To complete this tutorial, you need Python installed on your development machine. Check the Azure IoT Python SDK for current Python version requirements. You can check your Python version with the following command:

python --version

You can download the latest recommended version for multiple platforms from python.org.

In your local Python environment, install the package as follows:

pip install azure-iot-device

Clone the Python SDK IoT repository:

git clone --branch v2 https://github.com/Azure/azure-iot-sdk-python

Run the sample device

The azure-iot-sdk-python/samples/pnp folder contains the sample code for the IoT Plug and Play device. This tutorial uses the simple_thermostat.py file. This sample code implements an IoT Plug and Play compatible device and uses the Azure IoT Python Device Client Library.

Open the simple_thermostat.py file in a text editor. Notice how it:

  1. Defines a single device twin model identifier (DTMI) that uniquely represents the Thermostat. A DTMI must be known to the user and varies dependent on the scenario of device implementation. For the current sample, the model represents a thermostat that has telemetry, properties, and commands associated with monitoring temperature.

  2. Has functions to define command handler implementations. You write these handlers to define how the device responds to command requests.

  3. Has a function to define a command response. You create command response functions to send a response back to your IoT hub.

  4. Defines an input keyboard listener function to let you quit the application.

  5. Has a main function. The main function:

    1. Uses the device SDK to create a device client and connect to your IoT hub.

    2. Updates properties. The Thermostat model defines targetTemperature and maxTempSinceLastReboot as the two properties for the Thermostat. Properties are updated using the patch_twin_reported_properties method defined on the device_client.

    3. Starts listening for command requests using the execute_command_listener function. The function sets up a 'listener' to listen for commands coming from the service. When you set up the listener, you provide a method_name, user_command_handler, and create_user_response_handler.

      • The user_command_handler function defines what the device should do when it receives a command.
      • The create_user_response_handler function creates a response to be sent to your IoT hub when a command executes successfully. You can view this response in the portal.
    4. Starts sending telemetry. The pnp_send_telemetry is defined in the pnp_methods.py file. The sample code uses a loop to call this function every eight seconds.

    5. Disables all the listeners and tasks, and exist the loop when you press Q or q.

In Set up your environment, you created four environment variables to configure the sample to use the Device Provisioning Service (DPS) to connect to your IoT hub:

  • IOTHUB_DEVICE_SECURITY_TYPE with the value DPS
  • IOTHUB_DEVICE_DPS_ID_SCOPE with the DPS ID scope.
  • IOTHUB_DEVICE_DPS_DEVICE_ID with the value my-pnp-device.
  • IOTHUB_DEVICE_DPS_DEVICE_KEY with the enrollment primary key.
  • IOTHUB_DEVICE_DPS_ENDPOINT with the value global.azure-devices-provisioning.net.

To learn more about the sample configuration, see the sample readme.

Now that you've seen the code, use the following command to run the sample:

python simple_thermostat.py

You see the following output, which indicates the device is sending telemetry data to the hub, and is now ready to receive commands and property updates:

Listening for command requests and property updates
Press Q to quit
Sending telemetry for temperature
Sent message

Keep the sample running as you complete the next steps.

Use Azure IoT explorer to validate the code

After the device client sample starts, use the Azure IoT explorer tool to verify it's working.

  1. Open Azure IoT explorer.

  2. On the IoT hubs page, if you haven't already added a connection to your IoT hub, select + Add connection. Enter the connection string for the IoT hub you created previously and select Save.

  3. On the IoT Plug and Play Settings page, select + Add > Local folder and select the local models folder where you saved your model files.

  4. On the IoT hubs page, click on the name of the hub you want to work with. You see a list of devices registered to the IoT hub.

  5. Click on the Device ID of the device you created previously.

  6. The menu on the left shows the different types of information available for the device.

  7. Select IoT Plug and Play components to view the model information for your device.

  8. You can view the different components of the device. The default component and any extra ones. Select a component to work with.

  9. Select the Telemetry page and then select Start to view the telemetry data the device is sending for this component.

  10. Select the Properties (read-only) page to view the read-only properties reported for this component.

  11. Select the Properties (writable) page to view the writable properties you can update for this component.

  12. Select a property by it's name, enter a new value for it, and select Update desired value.

  13. To see the new value show up select the Refresh button.

  14. Select the Commands page to view all the commands for this component.

  15. Select the command you want to test set the parameter if any. Select Send command to call the command on the device. You can see your device respond to the command in the command prompt window where the sample code is running.

Clean up resources

If you've finished with the quickstarts and tutorials, see Clean up resources.

If you're developing for constrained devices, you can use IoT Plug and Play with:

This article includes links and resources for these constrained scenarios.

Prerequisites

Many of the samples below require a specific hardware device and the prerequisites are different for each of the samples. Follow the link to the relevant sample for detailed prerequisites, configuration, and build instructions.

Use the SDK for Embedded C

The SDK for Embedded C offers a lightweight solution to connect constrained devices to Azure IoT services, including using the IoT Plug and Play conventions. The following links include samples for MCU-based devices and for educational and debugging purposes.

Use an MCU-based device

For a complete end-to-end tutorial using the SDK for Embedded C, the Device Provisioning Service, and IoT Plug and Play on an MCU, see Repurpose PIC-IoT Wx Development Board to Connect to Azure through IoT Hub Device Provisioning Service.

Introductory samples

The SDK for Embedded C repository contains several samples that show you how to use IoT Plug and Play:

Note

These samples are shown running on Windows and Linux for educational and debugging purposes. In a production scenario, the samples are intended for constrained devices only.

Using Azure RTOS

Azure RTOS includes a lightweight layer that adds native connectivity to Azure IoT cloud services. This layer provides a simple mechanism to connect constrained devices to Azure IoT while using the advanced features of Azure RTOS. To learn more, see the What is Microsoft Azure RTOS.

Toolchains

The Azure RTOS samples are provided with different kinds of IDE and toolchain combinations, such as:

Samples

The following table lists samples that show you how to get started on different devices with Azure RTOS and IoT Plug and Play:

Manufacturer Device Samples
Microchip ATSAME54-XPRO GCC/CMakeIARMPLAB
MXCHIP AZ3166 GCC/CMake
NXP MIMXRT1060-EVK GCC/CMakeIARMCUXpresso
STMicroelectronics 32F746GDISCOVERY IARSTM32Cube
STMicroelectronics B-L475E-IOT01 GCC/CMakeIARSTM32Cube
STMicroelectronics B-L4S5I-IOT01 GCC/CMakeIARSTM32Cube

Next steps

In this tutorial, you've learned how to connect an IoT Plug and Play device to an IoT hub. To learn more about how to build a solution that interacts with your IoT Plug and Play devices, see: