Quickstart: Send telemetry from an IoT Plug and Play device to Azure IoT Hub

Applies to: Device application developers

Browse code

In this quickstart, you learn a basic Azure IoT application development workflow. You use the Azure CLI and IoT Explorer to create an Azure IoT hub and a device. Then you use an Azure IoT device SDK sample to run a simulated temperature controller, connect it securely to the hub, and send telemetry.

Prerequisites

This quickstart runs on Windows, Linux, and Raspberry Pi. It's been tested on the following OS and device versions:

  • Windows 10
  • Ubuntu 20.04 LTS
  • Raspberry Pi OS version 10 (Raspian) running on a Raspberry Pi 3 Model B+

Install the following prerequisites on your development machine except where noted for Raspberry Pi:

  • If you don't have an Azure subscription, create one for free before you begin.
  • Git.
  • Azure IoT Explorer: Cross-platform, GUI-based utility to monitor and manage Azure IoT. If you're using Raspberry Pi as your development platform, we recommend that you install IoT Explorer on another computer. If you don't want to install IoT Explorer, you can use Azure CLI to perform the same steps.
  • Azure CLI. You have two options for running Azure CLI commands in this quickstart:
    • Use the Azure Cloud Shell, an interactive shell that runs CLI commands in your browser. This option is recommended because you don't need to install anything. If you're using Cloud Shell for the first time, log into the Azure portal. Follow the steps in Cloud Shell quickstart to Start Cloud Shell and Select the Bash environment.
    • Optionally, run Azure CLI on your local machine. If Azure CLI is already installed, run az upgrade to upgrade the CLI and extensions to the current version. To install Azure CLI, see Install Azure CLI. If you're using Raspberry Pi as your development platform, we recommend that you use Azure Cloud Shell or install Azure CLI on another computer.

Install the remaining prerequisites for your operating system.

Linux or Raspberry Pi OS

To complete this quickstart on Linux or Raspberry Pi OS, install the following software:

Install GCC, Git, cmake, and 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 quickstart on Windows, install Visual Studio 2019 and add the required components for C and C++ development.

  1. For new users, install Visual Studio (Community, Professional, or Enterprise) 2019. Download the edition you want to install, and start the installer.

    Note

    For existing Visual Studio 2019 users, select Windows Start, type Visual Studio Installer, and start the installer.

  2. In the installer Workloads tab, select the Desktop Development with C++ workload.
  3. Run the installation.

Create an IoT hub

In this section, you use Azure CLI to create an IoT hub and a resource group. An Azure resource group is a logical container into which Azure resources are deployed and managed. An IoT hub acts as a central message hub for bi-directional communication between your IoT application and devices.

To create an IoT hub and a resource group:

  1. Launch Azure CLI:

    • If you're using Cloud Shell, select the Try It button on the CLI commands to launch Cloud Shell in a split browser window. Or you can open the Cloud Shell in a separate browser tab.
    • If you're using Azure CLI locally, open a console such as Windows CMD, PowerShell, or Bash and sign in to Azure CLI.

    To run the CLI commands in the rest of this quickstart: copy the command syntax, paste it into your Cloud Shell window or CLI console, edit variable values, and press Enter.

  2. Run az extension add to install or upgrade the azure-iot extension to the current version.

    az extension add --upgrade --name azure-iot
    
  3. Run the az group create command to create a resource group. The following command creates a resource group named MyResourceGroup in the eastus location.

    Note

    You can optionally set an alternate location. To see available locations, run az account list-locations. This tutorial uses eastus as shown in the example command.

    az group create --name MyResourceGroup --location eastus
    
  4. Run the az iot hub create command to create an IoT hub. It might take a few minutes to create an IoT hub.

    YourIotHubName. Replace this placeholder and the surrounding braces in the following command, using the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. Use your IoT hub name in the rest of this quickstart wherever you see the placeholder.

    az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
    

    Tip

    After creating an IoT hub, you'll use Azure IoT Explorer to interact with your IoT hub in the rest of this quickstart. IoT Explorer is a GUI application that lets you connect to an existing IoT Hub and add, manage, and monitor devices. To learn more, see Install and use Azure IoT explorer. Optionally, you can continue to use CLI commands.

Configure IoT Explorer

In the rest of this quickstart, you'll use IoT Explorer to register a device to your IoT hub and to view the device telemetry. In this section, you configure IoT Explorer to connect to the IoT hub you just created and to read plug and play models from the public model repository.

Note

You can also use the Azure CLI to register a device. Use the az iot hub device-identity create --device-id mydevice --hub-name {YourIoTHubName} command to register a new device and the az iot hub device-identity connection-string show --device-id mydevice --hub-name {YourIoTHubName} command to get the primary connection string for the device. Once you note down the device connection string, you can skip ahead to Run a simulated device.

To add a connection to your IoT hub:

  1. Run the az iot hub connection-string show command to get the connection string for your IoT hub.

    az iot hub connection-string  show --hub-name {YourIoTHubName}
    
  2. Copy the connection string without the surrounding quotation characters.

  3. In Azure IoT Explorer, select IoT hubs on the left menu, then select + Add connection.

  4. Paste the connection string into the Connection string box.

  5. Select Save.

    Screenshot of adding a connection in IoT Explorer

  6. If the connection succeeds, IoT Explorer switches to the Devices view.

To add the public model repository:

  1. In IoT Explorer, select Home to return to the home view.

  2. On the left menu, select IoT Plug and Play Settings, then select +Add and select Public repository from the drop-down menu.

  3. An entry appears for the public model repository at https://devicemodels.azure.com.

    Screenshot of adding the public model repository in IoT Explorer

  4. Select Save.

Register a device

In this section, you create a new device instance and register it with the IoT hub you created. You'll use the connection information for the newly registered device to securely connect your simulated device in a later section.

To register a device:

  1. From the home view in IoT Explorer, select IoT hubs.

  2. The connection you previously added should appear. Select View devices in this hub below the connection properties.

  3. Select + New and enter a device ID for your device; for example, mydevice. Leave all other properties the same.

  4. Select Create.

    Screenshot of Azure IoT Explorer device identity

  5. Use the copy buttons to copy and note down the Primary connection string field. You'll need this connection string later.

Run a simulated device

In this section, you use the C SDK to send messages from a simulated device to your IoT hub. You'll run a sample that implements a temperature controller with two thermostat sensors.

Build the sample

  1. Open a new console to install the Azure IoT C device SDK and run the code sample. For Windows, select Start, type Developer Command Prompt for VS 2019, and open the console. For Linux and Raspberry Pi OS, open a terminal for Bash commands.

    Note

    If you're using a local installation of Azure CLI, you might now have two console windows open. Be sure to enter the commands in this section in the console you just opened, not the one that you've been using for the CLI.

  2. Navigate to a local folder where you want to clone the sample repo.

  3. Clone the Azure IoT C device SDK to your local machine:

    git clone https://github.com/Azure/azure-iot-sdk-c.git
    
  4. Navigate to the root folder of the SDK, and run the following command to update dependencies:

    cd azure-iot-sdk-c
    git submodule update --init
    

    This operation takes a few minutes.

  5. To build the SDK and samples, run the following commands:

    cmake -Bcmake -Duse_prov_client=ON -Dhsm_type_symm_key=ON -Drun_e2e_tests=OFF
    cmake --build cmake
    
  6. Set the following environment variables, to enable your simulated device to connect to Azure IoT.

    • Set an environment variable called IOTHUB_DEVICE_CONNECTION_STRING. For the variable value, use the device connection string that you saved in the previous section.
    • Set an environment variable called IOTHUB_DEVICE_SECURITY_TYPE. For the variable, use the literal string value connectionString.

    CMD

    set IOTHUB_DEVICE_CONNECTION_STRING=<your connection string here>
    set IOTHUB_DEVICE_SECURITY_TYPE=connectionString
    

    Note

    For Windows CMD there are no quotation marks surrounding the string values for each variable.

    Bash

    export IOTHUB_DEVICE_CONNECTION_STRING="<your connection string here>"
    export IOTHUB_DEVICE_SECURITY_TYPE="connectionString"
    

Run the code

  1. Run the sample code, using the appropriate command for your console.

    CMD

    cmake\iothub_client\samples\pnp\pnp_temperature_controller\Debug\pnp_temperature_controller.exe
    

    Bash

    cmake/iothub_client/samples/pnp/pnp_temperature_controller/pnp_temperature_controller
    

    Note

    This code sample uses Azure IoT Plug and Play, which lets you integrate smart devices into your solutions without any manual configuration. By default, most samples in this documentation use IoT Plug and Play. To learn more about the advantages of IoT PnP, and cases for using or not using it, see What is IoT Plug and Play?.

The sample securely connects to your IoT hub as the device you registered and begins sending telemetry messages. The sample output appears in your console.

View telemetry

You can view the device telemetry with IoT Explorer. Optionally, you can view telemetry using Azure CLI.

To view telemetry in Azure IoT Explorer:

  1. From your Iot hub in IoT Explorer, select View devices in this hub, then select your device from the list.

  2. On the left menu for your device, select Telemetry.

  3. Confirm that Use built-in event hub is set to Yes and then select Start.

  4. View the telemetry as the device sends messages to the cloud.

    Screenshot of device telemetry in IoT Explorer

  5. Select Stop to end receiving events.

To read telemetry sent by individual device components, you can use the plug and play features in IoT Explorer. For example, the temperature controller in this quickstart has two thermostats: thermostat1 and thermostat2. To see the temperature reported by thermostat1:

  1. On your device in IoT Explorer, select IoT Plug and Play components from the left menu. Then select thermostat1 from the list of components.

  2. On the thermostat1 component pane, select Telemetry from the top menu.

  3. On the Telemetry pane, follow the same steps that you did previously. Make sure that Use built-in event hub is set to Yes and then select Start.

To view device telemetry with Azure CLI:

  1. Run the az iot hub monitor-events command to monitor events sent from the simulated device to your IoT hub. Use the names that you created previously in Azure IoT for your device and IoT hub.

    az iot hub monitor-events --output table --device-id mydevice --hub-name {YourIoTHubName}
    
  2. View the connection details and telemetry output in the console.

    Starting event monitor, filtering on device: mydevice, use ctrl-c to stop...
    event:
      component: ''
      interface: dtmi:com:example:TemperatureController;1
      module: ''
      origin: mydevice
      payload: '{"workingSet":1251}'
    
    event:
      component: thermostat1
      interface: dtmi:com:example:TemperatureController;1
      module: ''
      origin: mydevice
      payload: '{"temperature":22.00}'
    

Browse code

In this quickstart, you learn a basic Azure IoT application development workflow. You use the Azure CLI and IoT Explorer to create an Azure IoT hub and a device. Then you use an Azure IoT device SDK sample to run a simulated temperature controller, connect it securely to the hub, and send telemetry.

Prerequisites

This quickstart runs on Windows, Linux, and Raspberry Pi. It's been tested on the following OS and device versions:

  • Windows 10
  • Ubuntu 20.04 LTS
  • Raspberry Pi OS version 10 (Raspian) running on a Raspberry Pi 3 Model B+

Install the following prerequisites on your development machine except where noted for Raspberry Pi:

  • If you don't have an Azure subscription, create one for free before you begin.

  • Git.

  • .NET Core SDK 3.1. Be sure to install the .NET SDK, not just the runtime. To check the version of the .NET SDK and runtime installed on your machine, run dotnet --info.

    • For Windows and Linux (except Raspberry Pi), follow the instructions to install the .NET Core SDK 3.1 on your platform.
    • For Raspberry Pi, you'll need to follow the instructions to manually install the SDK. This is because on Debian, package manager installs of the .NET SDK are only supported for the x64 architecture.
  • Azure IoT Explorer: Cross-platform, GUI-based utility to monitor and manage Azure IoT. If you're using Raspberry Pi as your development platform, we recommend that you install IoT Explorer on another computer. If you don't want to install IoT Explorer, you can use Azure CLI to perform the same steps.

  • Azure CLI. You have two options for running Azure CLI commands in this quickstart:

    • Use the Azure Cloud Shell, an interactive shell that runs CLI commands in your browser. This option is recommended because you don't need to install anything. If you're using Cloud Shell for the first time, log into the Azure portal. Follow the steps in Cloud Shell quickstart to Start Cloud Shell and Select the Bash environment.
    • Optionally, run Azure CLI on your local machine. If Azure CLI is already installed, run az upgrade to upgrade the CLI and extensions to the current version. To install Azure CLI, see Install Azure CLI. If you're using Raspberry Pi as your development platform, we recommend that you use Azure Cloud Shell or install Azure CLI on another computer.

Create an IoT hub

In this section, you use Azure CLI to create an IoT hub and a resource group. An Azure resource group is a logical container into which Azure resources are deployed and managed. An IoT hub acts as a central message hub for bi-directional communication between your IoT application and devices.

To create an IoT hub and a resource group:

  1. Launch Azure CLI:

    • If you're using Cloud Shell, select the Try It button on the CLI commands to launch Cloud Shell in a split browser window. Or you can open the Cloud Shell in a separate browser tab.
    • If you're using Azure CLI locally, open a console such as Windows CMD, PowerShell, or Bash and sign in to Azure CLI.

    To run the CLI commands in the rest of this quickstart: copy the command syntax, paste it into your Cloud Shell window or CLI console, edit variable values, and press Enter.

  2. Run az extension add to install or upgrade the azure-iot extension to the current version.

    az extension add --upgrade --name azure-iot
    
  3. Run the az group create command to create a resource group. The following command creates a resource group named MyResourceGroup in the eastus location.

    Note

    You can optionally set an alternate location. To see available locations, run az account list-locations. This tutorial uses eastus as shown in the example command.

    az group create --name MyResourceGroup --location eastus
    
  4. Run the az iot hub create command to create an IoT hub. It might take a few minutes to create an IoT hub.

    YourIotHubName. Replace this placeholder and the surrounding braces in the following command, using the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. Use your IoT hub name in the rest of this quickstart wherever you see the placeholder.

    az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
    

    Tip

    After creating an IoT hub, you'll use Azure IoT Explorer to interact with your IoT hub in the rest of this quickstart. IoT Explorer is a GUI application that lets you connect to an existing IoT Hub and add, manage, and monitor devices. To learn more, see Install and use Azure IoT explorer. Optionally, you can continue to use CLI commands.

Configure IoT Explorer

In the rest of this quickstart, you'll use IoT Explorer to register a device to your IoT hub and to view the device telemetry. In this section, you configure IoT Explorer to connect to the IoT hub you just created and to read plug and play models from the public model repository.

Note

You can also use the Azure CLI to register a device. Use the az iot hub device-identity create --device-id mydevice --hub-name {YourIoTHubName} command to register a new device and the az iot hub device-identity connection-string show --device-id mydevice --hub-name {YourIoTHubName} command to get the primary connection string for the device. Once you note down the device connection string, you can skip ahead to Run a simulated device.

To add a connection to your IoT hub:

  1. Run the az iot hub connection-string show command to get the connection string for your IoT hub.

    az iot hub connection-string  show --hub-name {YourIoTHubName}
    
  2. Copy the connection string without the surrounding quotation characters.

  3. In Azure IoT Explorer, select IoT hubs on the left menu, then select + Add connection.

  4. Paste the connection string into the Connection string box.

  5. Select Save.

    Screenshot of adding a connection in IoT Explorer

  6. If the connection succeeds, IoT Explorer switches to the Devices view.

To add the public model repository:

  1. In IoT Explorer, select Home to return to the home view.

  2. On the left menu, select IoT Plug and Play Settings, then select +Add and select Public repository from the drop-down menu.

  3. An entry appears for the public model repository at https://devicemodels.azure.com.

    Screenshot of adding the public model repository in IoT Explorer

  4. Select Save.

Register a device

In this section, you create a new device instance and register it with the IoT hub you created. You'll use the connection information for the newly registered device to securely connect your simulated device in a later section.

To register a device:

  1. From the home view in IoT Explorer, select IoT hubs.

  2. The connection you previously added should appear. Select View devices in this hub below the connection properties.

  3. Select + New and enter a device ID for your device; for example, mydevice. Leave all other properties the same.

  4. Select Create.

    Screenshot of Azure IoT Explorer device identity

  5. Use the copy buttons to copy and note down the Primary connection string field. You'll need this connection string later.

Run a simulated device

In this section, you'll use the C# SDK to send messages from a simulated device to your IoT hub. You'll run a sample that implements a temperature controller with two thermostat sensors.

  1. Open a new console such as Windows CMD, PowerShell, or Bash. In the following steps, you'll use this console to install the Node.js SDK and work with Node.js sample code.

    Note

    If you're using a local installation of Azure CLI, you might now have two console windows open. Be sure to enter the commands in this section in the console you just opened, not the one that you've been using for the CLI.

  2. Clone the Microsoft Azure IoT Samples for C# (.NET) to your local machine:

    git clone https://github.com/Azure-Samples/azure-iot-samples-csharp.git
    
  3. Navigate to the sample directory:

    Windows

    cd azure-iot-samples-csharp\iot-hub\Samples\device\PnpDeviceSamples\TemperatureController
    

    Linux or Raspberry Pi OS

    cd azure-iot-samples-csharp/iot-hub/Samples/device/PnpDeviceSamples/TemperatureController
    
  4. Install the Azure IoT C# SDK and necessary dependencies:

    dotnet restore
    

    This command installs the proper dependencies as specified in the TemperatureController.csproj file.

  5. Set both of the following environment variables, to enable your simulated device to connect to Azure IoT.

    • Set an environment variable called IOTHUB_DEVICE_CONNECTION_STRING. For the variable value, use the device connection string that you saved in the previous section.
    • Set an environment variable called IOTHUB_DEVICE_SECURITY_TYPE. For the variable, use the literal string value connectionString.

    CMD (Windows)

    set IOTHUB_DEVICE_CONNECTION_STRING=<your connection string here>
    set IOTHUB_DEVICE_SECURITY_TYPE=connectionString
    

    Note

    For Windows CMD there are no quotation marks surrounding the string values for each variable.

    PowerShell

    $env:IOTHUB_DEVICE_CONNECTION_STRING='<your connection string here>'
    $env:IOTHUB_DEVICE_SECURITY_TYPE='connectionString'
    

    Bash

    export IOTHUB_DEVICE_CONNECTION_STRING="<your connection string here>"
    export IOTHUB_DEVICE_SECURITY_TYPE="connectionString"
    
  6. Run the code sample:

    dotnet run
    

    Note

    This code sample uses Azure IoT Plug and Play, which lets you integrate smart devices into your solutions without any manual configuration. By default, most samples in this documentation use IoT Plug and Play. To learn more about the advantages of IoT PnP, and cases for using or not using it, see What is IoT Plug and Play?.

The sample securely connects to your IoT hub as the device you registered and begins sending telemetry messages. The sample output appears in your console.

View telemetry

You can view the device telemetry with IoT Explorer. Optionally, you can view telemetry using Azure CLI.

To view telemetry in Azure IoT Explorer:

  1. From your Iot hub in IoT Explorer, select View devices in this hub, then select your device from the list.

  2. On the left menu for your device, select Telemetry.

  3. Confirm that Use built-in event hub is set to Yes and then select Start.

  4. View the telemetry as the device sends messages to the cloud.

    Screenshot of device telemetry in IoT Explorer

  5. Select Stop to end receiving events.

To read telemetry sent by individual device components, you can use the plug and play features in IoT Explorer. For example, the temperature controller in this quickstart has two thermostats: thermostat1 and thermostat2. To see the temperature reported by thermostat1:

  1. On your device in IoT Explorer, select IoT Plug and Play components from the left menu. Then select thermostat1 from the list of components.

  2. On the thermostat1 component pane, select Telemetry from the top menu.

  3. On the Telemetry pane, follow the same steps that you did previously. Make sure that Use built-in event hub is set to Yes and then select Start.

To view device telemetry with Azure CLI:

  1. Run the az iot hub monitor-events command to monitor events sent from the simulated device to your IoT hub. Use the names that you created previously in Azure IoT for your device and IoT hub.

    az iot hub monitor-events --output table --device-id mydevice --hub-name {YourIoTHubName}
    
  2. View the connection details and telemetry output in the console.

    Starting event monitor, filtering on device: mydevice, use ctrl-c to stop...
    event:
      component: thermostat1
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 39.8
    
    event:
      component: thermostat2
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 36.7
    
  3. Select CTRL+C to end monitoring.

Browse code

In this quickstart, you learn a basic Azure IoT application development workflow. You use the Azure CLI and IoT Explorer to create an Azure IoT hub and a device. Then you use an Azure IoT device SDK sample to run a simulated temperature controller, connect it securely to the hub, and send telemetry.

Prerequisites

  • If you don't have an Azure subscription, create one for free before you begin.
  • Git.
  • A development machine with Java SE Development Kit 8 or later. You can download the Java 8 (LTS) JDK for multiple platforms from Download Zulu Builds of OpenJDK. In the installer, select the Add to Path option.
  • Apache Maven 3. After you extract the download to a local folder, add the full path to the Maven /bin folder to the Windows PATH variable.
  • Azure IoT Explorer: Cross-platform, GUI-based utility to monitor and manage Azure IoT.
  • Azure CLI. You have two options for running Azure CLI commands in this quickstart:
    • Use the Azure Cloud Shell, an interactive shell that runs CLI commands in your browser. This option is recommended because you don't need to install anything. If you're using Cloud Shell for the first time, log into the Azure portal. Follow the steps in Cloud Shell quickstart to Start Cloud Shell and Select the Bash environment.
    • Optionally, run Azure CLI on your local machine. If Azure CLI is already installed, run az upgrade to upgrade the CLI and extensions to the current version. To install Azure CLI, see Install Azure CLI.

Create an IoT hub

In this section, you use Azure CLI to create an IoT hub and a resource group. An Azure resource group is a logical container into which Azure resources are deployed and managed. An IoT hub acts as a central message hub for bi-directional communication between your IoT application and devices.

To create an IoT hub and a resource group:

  1. Launch Azure CLI:

    • If you're using Cloud Shell, select the Try It button on the CLI commands to launch Cloud Shell in a split browser window. Or you can open the Cloud Shell in a separate browser tab.
    • If you're using Azure CLI locally, open a console such as Windows CMD, PowerShell, or Bash and sign in to Azure CLI.

    To run the CLI commands in the rest of this quickstart: copy the command syntax, paste it into your Cloud Shell window or CLI console, edit variable values, and press Enter.

  2. Run az extension add to install or upgrade the azure-iot extension to the current version.

    az extension add --upgrade --name azure-iot
    
  3. Run the az group create command to create a resource group. The following command creates a resource group named MyResourceGroup in the eastus location.

    Note

    You can optionally set an alternate location. To see available locations, run az account list-locations. This tutorial uses eastus as shown in the example command.

    az group create --name MyResourceGroup --location eastus
    
  4. Run the az iot hub create command to create an IoT hub. It might take a few minutes to create an IoT hub.

    YourIotHubName. Replace this placeholder and the surrounding braces in the following command, using the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. Use your IoT hub name in the rest of this quickstart wherever you see the placeholder.

    az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
    

    Tip

    After creating an IoT hub, you'll use Azure IoT Explorer to interact with your IoT hub in the rest of this quickstart. IoT Explorer is a GUI application that lets you connect to an existing IoT Hub and add, manage, and monitor devices. To learn more, see Install and use Azure IoT explorer. Optionally, you can continue to use CLI commands.

Configure IoT Explorer

In the rest of this quickstart, you'll use IoT Explorer to register a device to your IoT hub and to view the device telemetry. In this section, you configure IoT Explorer to connect to the IoT hub you just created and to read plug and play models from the public model repository.

Note

You can also use the Azure CLI to register a device. Use the az iot hub device-identity create --device-id mydevice --hub-name {YourIoTHubName} command to register a new device and the az iot hub device-identity connection-string show --device-id mydevice --hub-name {YourIoTHubName} command to get the primary connection string for the device. Once you note down the device connection string, you can skip ahead to Run a simulated device.

To add a connection to your IoT hub:

  1. Run the az iot hub connection-string show command to get the connection string for your IoT hub.

    az iot hub connection-string  show --hub-name {YourIoTHubName}
    
  2. Copy the connection string without the surrounding quotation characters.

  3. In Azure IoT Explorer, select IoT hubs on the left menu, then select + Add connection.

  4. Paste the connection string into the Connection string box.

  5. Select Save.

    Screenshot of adding a connection in IoT Explorer

  6. If the connection succeeds, IoT Explorer switches to the Devices view.

To add the public model repository:

  1. In IoT Explorer, select Home to return to the home view.

  2. On the left menu, select IoT Plug and Play Settings, then select +Add and select Public repository from the drop-down menu.

  3. An entry appears for the public model repository at https://devicemodels.azure.com.

    Screenshot of adding the public model repository in IoT Explorer

  4. Select Save.

Register a device

In this section, you create a new device instance and register it with the IoT hub you created. You'll use the connection information for the newly registered device to securely connect your simulated device in a later section.

To register a device:

  1. From the home view in IoT Explorer, select IoT hubs.

  2. The connection you previously added should appear. Select View devices in this hub below the connection properties.

  3. Select + New and enter a device ID for your device; for example, mydevice. Leave all other properties the same.

  4. Select Create.

    Screenshot of Azure IoT Explorer device identity

  5. Use the copy buttons to copy and note down the Primary connection string field. You'll need this connection string later.

Run a simulated device

In this section, you use the Java SDK to send messages from a simulated device to your IoT hub. You'll run a sample that implements a temperature controller with two thermostat sensors.

Configure your environment

  1. Open a console to install the Azure IoT Java device SDK, build, and run the code sample. You'll use this console in the following steps.

    Note

    If you're using a local installation of Azure CLI, you might now have two console windows open. Be sure to enter the commands in this section in the console you just opened, not the one that you've been using for the CLI.

  2. Set the following environment variables, to enable your simulated device to connect to Azure IoT.

    • Set an environment variable called IOTHUB_DEVICE_CONNECTION_STRING. For the variable value, use the device connection string that you saved in the previous section.
    • Set an environment variable called IOTHUB_DEVICE_SECURITY_TYPE. For the variable, use the literal string value connectionString.

    CMD

    set IOTHUB_DEVICE_CONNECTION_STRING=<your connection string here>
    set IOTHUB_DEVICE_SECURITY_TYPE=connectionString
    

    Note

    For Windows CMD there are no quotation marks surrounding the string values for each variable.

    Bash

    export IOTHUB_DEVICE_CONNECTION_STRING="<your connection string here>"
    export IOTHUB_DEVICE_SECURITY_TYPE="connectionString"
    

Build the sample

  1. Clone the Azure IoT Java device SDK to your local machine:
    git clone https://github.com/Azure/azure-iot-sdk-java.git
    
  2. Navigate to the root folder of the SDK, and run the following command to build the SDK and update the samples.
    cd azure-iot-sdk-java
    mvn install -T 2C -DskipTests
    
    This operation takes several minutes.

Run the code

  1. Navigate to the samples directory.

    cd device/iot-device-samples/pnp-device-sample/temperature-controller-device-sample
    
  2. Run the following code sample.

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

    Note

    This code sample uses Azure IoT Plug and Play, which lets you integrate smart devices into your solutions without any manual configuration. By default, most samples in this documentation use IoT Plug and Play. To learn more about the advantages of IoT PnP, and cases for using or not using it, see What is IoT Plug and Play?.

The sample securely connects to your IoT hub as the device you registered and begins sending telemetry messages. The sample output appears in your console.

View telemetry

You can view the device telemetry with IoT Explorer. Optionally, you can view telemetry using Azure CLI.

To view telemetry in Azure IoT Explorer:

  1. From your Iot hub in IoT Explorer, select View devices in this hub, then select your device from the list.

  2. On the left menu for your device, select Telemetry.

  3. Confirm that Use built-in event hub is set to Yes and then select Start.

  4. View the telemetry as the device sends messages to the cloud.

    Screenshot of device telemetry in IoT Explorer

  5. Select Stop to end receiving events.

To read telemetry sent by individual device components, you can use the plug and play features in IoT Explorer. For example, the temperature controller in this quickstart has two thermostats: thermostat1 and thermostat2. To see the temperature reported by thermostat1:

  1. On your device in IoT Explorer, select IoT Plug and Play components from the left menu. Then select thermostat1 from the list of components.

  2. On the thermostat1 component pane, select Telemetry from the top menu.

  3. On the Telemetry pane, follow the same steps that you did previously. Make sure that Use built-in event hub is set to Yes and then select Start.

To view device telemetry with Azure CLI:

  1. Run the az iot hub monitor-events command to monitor events sent from the simulated device to your IoT hub. Use the names that you created previously in Azure IoT for your device and IoT hub.

    az iot hub monitor-events --output table --device-id mydevice --hub-name {YourIoTHubName}
    
  2. View the connection details and telemetry output in the console.

    Starting event monitor, filtering on device: mydevice, use ctrl-c to stop...
    event:
      component: thermostat1
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 24.1
    
    event:
      component: thermostat2
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 33.3
    

Browse code

In this quickstart, you learn a basic Azure IoT application development workflow. You use the Azure CLI and IoT Explorer to create an Azure IoT hub and a device. Then you use an Azure IoT device SDK sample to run a simulated temperature controller, connect it securely to the hub, and send telemetry.

Prerequisites

This quickstart runs on Windows, Linux, and Raspberry Pi. It's been tested on the following OS and device versions:

  • Windows 10
  • Ubuntu 20.04 LTS
  • Raspberry Pi OS version 10 (Raspian) running on a Raspberry Pi 3 Model B+

Install the following prerequisites on your development machine except where noted for Raspberry Pi:

  • If you don't have an Azure subscription, create one for free before you begin.
  • Git.
  • Node.js version 10 or later. To check your node version run node --version.
  • Azure IoT Explorer: Cross-platform, GUI-based utility to monitor and manage Azure IoT. If you're using Raspberry Pi as your development platform, we recommend that you install IoT Explorer on another computer. If you don't want to install IoT Explorer, you can use Azure CLI to perform the same steps.
  • Azure CLI. You have two options for running Azure CLI commands in this quickstart:
    • Use the Azure Cloud Shell, an interactive shell that runs CLI commands in your browser. This option is recommended because you don't need to install anything. If you're using Cloud Shell for the first time, log into the Azure portal. Follow the steps in Cloud Shell quickstart to Start Cloud Shell and Select the Bash environment.
    • Optionally, run Azure CLI on your local machine. If Azure CLI is already installed, run az upgrade to upgrade the CLI and extensions to the current version. To install Azure CLI, see Install Azure CLI. If you're using Raspberry Pi as your development platform, we recommend that you use Azure Cloud Shell or install Azure CLI on another computer.

Create an IoT hub

In this section, you use Azure CLI to create an IoT hub and a resource group. An Azure resource group is a logical container into which Azure resources are deployed and managed. An IoT hub acts as a central message hub for bi-directional communication between your IoT application and devices.

To create an IoT hub and a resource group:

  1. Launch Azure CLI:

    • If you're using Cloud Shell, select the Try It button on the CLI commands to launch Cloud Shell in a split browser window. Or you can open the Cloud Shell in a separate browser tab.
    • If you're using Azure CLI locally, open a console such as Windows CMD, PowerShell, or Bash and sign in to Azure CLI.

    To run the CLI commands in the rest of this quickstart: copy the command syntax, paste it into your Cloud Shell window or CLI console, edit variable values, and press Enter.

  2. Run az extension add to install or upgrade the azure-iot extension to the current version.

    az extension add --upgrade --name azure-iot
    
  3. Run the az group create command to create a resource group. The following command creates a resource group named MyResourceGroup in the eastus location.

    Note

    You can optionally set an alternate location. To see available locations, run az account list-locations. This tutorial uses eastus as shown in the example command.

    az group create --name MyResourceGroup --location eastus
    
  4. Run the az iot hub create command to create an IoT hub. It might take a few minutes to create an IoT hub.

    YourIotHubName. Replace this placeholder and the surrounding braces in the following command, using the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. Use your IoT hub name in the rest of this quickstart wherever you see the placeholder.

    az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
    

    Tip

    After creating an IoT hub, you'll use Azure IoT Explorer to interact with your IoT hub in the rest of this quickstart. IoT Explorer is a GUI application that lets you connect to an existing IoT Hub and add, manage, and monitor devices. To learn more, see Install and use Azure IoT explorer. Optionally, you can continue to use CLI commands.

Configure IoT Explorer

In the rest of this quickstart, you'll use IoT Explorer to register a device to your IoT hub and to view the device telemetry. In this section, you configure IoT Explorer to connect to the IoT hub you just created and to read plug and play models from the public model repository.

Note

You can also use the Azure CLI to register a device. Use the az iot hub device-identity create --device-id mydevice --hub-name {YourIoTHubName} command to register a new device and the az iot hub device-identity connection-string show --device-id mydevice --hub-name {YourIoTHubName} command to get the primary connection string for the device. Once you note down the device connection string, you can skip ahead to Run a simulated device.

To add a connection to your IoT hub:

  1. Run the az iot hub connection-string show command to get the connection string for your IoT hub.

    az iot hub connection-string  show --hub-name {YourIoTHubName}
    
  2. Copy the connection string without the surrounding quotation characters.

  3. In Azure IoT Explorer, select IoT hubs on the left menu, then select + Add connection.

  4. Paste the connection string into the Connection string box.

  5. Select Save.

    Screenshot of adding a connection in IoT Explorer

  6. If the connection succeeds, IoT Explorer switches to the Devices view.

To add the public model repository:

  1. In IoT Explorer, select Home to return to the home view.

  2. On the left menu, select IoT Plug and Play Settings, then select +Add and select Public repository from the drop-down menu.

  3. An entry appears for the public model repository at https://devicemodels.azure.com.

    Screenshot of adding the public model repository in IoT Explorer

  4. Select Save.

Register a device

In this section, you create a new device instance and register it with the IoT hub you created. You'll use the connection information for the newly registered device to securely connect your simulated device in a later section.

To register a device:

  1. From the home view in IoT Explorer, select IoT hubs.

  2. The connection you previously added should appear. Select View devices in this hub below the connection properties.

  3. Select + New and enter a device ID for your device; for example, mydevice. Leave all other properties the same.

  4. Select Create.

    Screenshot of Azure IoT Explorer device identity

  5. Use the copy buttons to copy and note down the Primary connection string field. You'll need this connection string later.

Run a simulated device

In this section, you'll use the Node.js SDK to send messages from a simulated device to your IoT hub. You'll run a sample that implements a temperature controller with two thermostat sensors.

  1. Open a new console such as Windows CMD, PowerShell, or Bash. In the following steps, you'll use this console to install the Node.js SDK and work with Node.js sample code.

    Note

    If you're using a local installation of Azure CLI, you might now have two console windows open. Be sure to enter the commands in this section in the console you just opened, not the one that you've been using for the CLI.

  2. Clone the Azure IoT Node.js SDK device samples to your local machine:

    git clone https://github.com/Azure/azure-iot-sdk-node
    
  3. Navigate to the sample directory:

    Windows

    cd azure-iot-sdk-node\device\samples\javascript\pnp
    

    Linux or Raspberry Pi OS

    cd azure-iot-sdk-node/device/samples/javascript/pnp
    
  4. Install the Azure IoT Node.js SDK and necessary dependencies:

    npm install
    

    This command installs the proper dependencies as specified in the package.json file in the device samples directory.

  5. Set both of the following environment variables, to enable your simulated device to connect to Azure IoT.

    • Set an environment variable called IOTHUB_DEVICE_CONNECTION_STRING. For the variable value, use the device connection string that you saved in the previous section.
    • Set an environment variable called IOTHUB_DEVICE_SECURITY_TYPE. For the variable, use the literal string value connectionString.

    CMD (Windows)

    set IOTHUB_DEVICE_CONNECTION_STRING=<your connection string here>
    set IOTHUB_DEVICE_SECURITY_TYPE=connectionString
    

    Note

    For Windows CMD there are no quotation marks surrounding the string values for each variable.

    PowerShell

    $env:IOTHUB_DEVICE_CONNECTION_STRING='<your connection string here>'
    $env:IOTHUB_DEVICE_SECURITY_TYPE='connectionString'
    

    Bash

    export IOTHUB_DEVICE_CONNECTION_STRING="<your connection string here>"
    export IOTHUB_DEVICE_SECURITY_TYPE="connectionString"
    
  6. Run the following code sample:

    node pnpTemperatureController.js
    

    Note

    This code sample uses Azure IoT Plug and Play, which lets you integrate smart devices into your solutions without any manual configuration. By default, most samples in this documentation use IoT Plug and Play. To learn more about the advantages of IoT PnP, and cases for using or not using it, see What is IoT Plug and Play?.

The sample securely connects to your IoT hub as the device you registered and begins sending telemetry messages. The sample output appears in your console.

View telemetry

You can view the device telemetry with IoT Explorer. Optionally, you can view telemetry using Azure CLI.

To view telemetry in Azure IoT Explorer:

  1. From your Iot hub in IoT Explorer, select View devices in this hub, then select your device from the list.

  2. On the left menu for your device, select Telemetry.

  3. Confirm that Use built-in event hub is set to Yes and then select Start.

  4. View the telemetry as the device sends messages to the cloud.

    Screenshot of device telemetry in IoT Explorer

  5. Select Stop to end receiving events.

To read telemetry sent by individual device components, you can use the plug and play features in IoT Explorer. For example, the temperature controller in this quickstart has two thermostats: thermostat1 and thermostat2. To see the temperature reported by thermostat1:

  1. On your device in IoT Explorer, select IoT Plug and Play components from the left menu. Then select thermostat1 from the list of components.

  2. On the thermostat1 component pane, select Telemetry from the top menu.

  3. On the Telemetry pane, follow the same steps that you did previously. Make sure that Use built-in event hub is set to Yes and then select Start.

To view device telemetry with Azure CLI:

  1. Run the az iot hub monitor-events command to monitor events sent from the simulated device to your IoT hub. Use the names that you created previously in Azure IoT for your device and IoT hub.

    az iot hub monitor-events --output table --device-id mydevice --hub-name {YourIoTHubName}
    
  2. View the connection details and telemetry output in the console.

    Starting event monitor, filtering on device: mydevice, use ctrl-c to stop...
    event:
      component: thermostat1
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 70.5897683228018
    
    event:
      component: thermostat2
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 52.87582619316418
    

Browse code

In this quickstart, you learn a basic Azure IoT application development workflow. You use the Azure CLI and IoT Explorer to create an Azure IoT hub and a device. Then you use an Azure IoT device SDK sample to run a simulated temperature controller, connect it securely to the hub, and send telemetry.

Prerequisites

This quickstart runs on Windows, Linux, and Raspberry Pi. It's been tested on the following OS and device versions:

  • Windows 10
  • Ubuntu 20.04 LTS
  • Raspberry Pi OS version 10 (Raspian) running on a Raspberry Pi 3 Model B+

Install the following prerequisites on your development machine except where noted for Raspberry Pi:

  • If you don't have an Azure subscription, create one for free before you begin.
  • Git.
  • Python version 3.7 or later. To check your Python version, run python3 --version.
  • Azure IoT Explorer: Cross-platform, GUI-based utility to monitor and manage Azure IoT. If you're using Raspberry Pi as your development platform, we recommend that you install IoT Explorer on another computer. If you don't want to install IoT Explorer, you can use Azure CLI to perform the same steps.
  • Azure CLI. You have two options for running Azure CLI commands in this quickstart:
    • Use the Azure Cloud Shell, an interactive shell that runs CLI commands in your browser. This option is recommended because you don't need to install anything. If you're using Cloud Shell for the first time, log into the Azure portal. Follow the steps in Cloud Shell quickstart to Start Cloud Shell and Select the Bash environment.
    • Optionally, run Azure CLI on your local machine. If Azure CLI is already installed, run az upgrade to upgrade the CLI and extensions to the current version. To install Azure CLI, see Install Azure CLI. If you're using Raspberry Pi as your development platform, we recommend that you use Azure Cloud Shell or install Azure CLI on another computer.

Create an IoT hub

In this section, you use Azure CLI to create an IoT hub and a resource group. An Azure resource group is a logical container into which Azure resources are deployed and managed. An IoT hub acts as a central message hub for bi-directional communication between your IoT application and devices.

To create an IoT hub and a resource group:

  1. Launch Azure CLI:

    • If you're using Cloud Shell, select the Try It button on the CLI commands to launch Cloud Shell in a split browser window. Or you can open the Cloud Shell in a separate browser tab.
    • If you're using Azure CLI locally, open a console such as Windows CMD, PowerShell, or Bash and sign in to Azure CLI.

    To run the CLI commands in the rest of this quickstart: copy the command syntax, paste it into your Cloud Shell window or CLI console, edit variable values, and press Enter.

  2. Run az extension add to install or upgrade the azure-iot extension to the current version.

    az extension add --upgrade --name azure-iot
    
  3. Run the az group create command to create a resource group. The following command creates a resource group named MyResourceGroup in the eastus location.

    Note

    You can optionally set an alternate location. To see available locations, run az account list-locations. This tutorial uses eastus as shown in the example command.

    az group create --name MyResourceGroup --location eastus
    
  4. Run the az iot hub create command to create an IoT hub. It might take a few minutes to create an IoT hub.

    YourIotHubName. Replace this placeholder and the surrounding braces in the following command, using the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. Use your IoT hub name in the rest of this quickstart wherever you see the placeholder.

    az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
    

    Tip

    After creating an IoT hub, you'll use Azure IoT Explorer to interact with your IoT hub in the rest of this quickstart. IoT Explorer is a GUI application that lets you connect to an existing IoT Hub and add, manage, and monitor devices. To learn more, see Install and use Azure IoT explorer. Optionally, you can continue to use CLI commands.

Configure IoT Explorer

In the rest of this quickstart, you'll use IoT Explorer to register a device to your IoT hub and to view the device telemetry. In this section, you configure IoT Explorer to connect to the IoT hub you just created and to read plug and play models from the public model repository.

Note

You can also use the Azure CLI to register a device. Use the az iot hub device-identity create --device-id mydevice --hub-name {YourIoTHubName} command to register a new device and the az iot hub device-identity connection-string show --device-id mydevice --hub-name {YourIoTHubName} command to get the primary connection string for the device. Once you note down the device connection string, you can skip ahead to Run a simulated device.

To add a connection to your IoT hub:

  1. Run the az iot hub connection-string show command to get the connection string for your IoT hub.

    az iot hub connection-string  show --hub-name {YourIoTHubName}
    
  2. Copy the connection string without the surrounding quotation characters.

  3. In Azure IoT Explorer, select IoT hubs on the left menu, then select + Add connection.

  4. Paste the connection string into the Connection string box.

  5. Select Save.

    Screenshot of adding a connection in IoT Explorer

  6. If the connection succeeds, IoT Explorer switches to the Devices view.

To add the public model repository:

  1. In IoT Explorer, select Home to return to the home view.

  2. On the left menu, select IoT Plug and Play Settings, then select +Add and select Public repository from the drop-down menu.

  3. An entry appears for the public model repository at https://devicemodels.azure.com.

    Screenshot of adding the public model repository in IoT Explorer

  4. Select Save.

Register a device

In this section, you create a new device instance and register it with the IoT hub you created. You'll use the connection information for the newly registered device to securely connect your simulated device in a later section.

To register a device:

  1. From the home view in IoT Explorer, select IoT hubs.

  2. The connection you previously added should appear. Select View devices in this hub below the connection properties.

  3. Select + New and enter a device ID for your device; for example, mydevice. Leave all other properties the same.

  4. Select Create.

    Screenshot of Azure IoT Explorer device identity

  5. Use the copy buttons to copy and note down the Primary connection string field. You'll need this connection string later.

Run a simulated device

In this section, you use the Python SDK to send messages from a simulated device to your IoT hub. You'll run a sample that implements a temperature controller with two thermostat sensors.

  1. Open a new console such as Windows CMD, PowerShell, or Bash. In the following steps, you'll use this console to install the Python SDK and work with the Python sample code.

    Note

    If you're using a local installation of Azure CLI, you might now have two console windows open. Be sure to enter the commands in this section in the console you just opened, not the one that you've been using for the CLI.

  2. Clone the Azure IoT Python SDK device samples to your local machine:

    git clone https://github.com/Azure/azure-iot-sdk-python
    
  3. Navigate to the sample directory:

    Windows

    cd azure-iot-sdk-python\azure-iot-device\samples\pnp
    

    Linux or Raspberry Pi OS

    cd azure-iot-sdk-python/azure-iot-device/samples/pnp
    
  4. Install the Azure IoT Python SDK:

    pip3 install azure-iot-device
    
  5. Set the following environment variables, to enable your simulated device to connect to Azure IoT.

    • Set an environment variable called IOTHUB_DEVICE_CONNECTION_STRING. For the variable value, use the device connection string that you saved in the previous section.
    • Set an environment variable called IOTHUB_DEVICE_SECURITY_TYPE. For the variable, use the literal string value connectionString.

    CMD (Windows)

    set IOTHUB_DEVICE_CONNECTION_STRING=<your connection string here>
    set IOTHUB_DEVICE_SECURITY_TYPE=connectionString
    

    Note

    For Windows CMD there are no quotation marks surrounding the string values for each variable.

    PowerShell

    $env:IOTHUB_DEVICE_CONNECTION_STRING='<your connection string here>'
    $env:IOTHUB_DEVICE_SECURITY_TYPE='connectionString'
    

    Bash

    export IOTHUB_DEVICE_CONNECTION_STRING="<your connection string here>"
    export IOTHUB_DEVICE_SECURITY_TYPE="connectionString"
    
  6. Run the code for the following sample file.

    python3 temp_controller_with_thermostats.py
    

    Note

    This code sample uses Azure IoT Plug and Play, which lets you integrate smart devices into your solutions without any manual configuration. By default, most samples in this documentation use IoT Plug and Play. To learn more about the advantages of IoT Plug and Play, and cases for using or not using it, see What is IoT Plug and Play?.

The sample securely connects to your IoT hub as the device you registered and begins sending telemetry messages. The sample output appears in your console.

View telemetry

You can view the device telemetry with IoT Explorer. Optionally, you can view telemetry using Azure CLI.

To view telemetry in Azure IoT Explorer:

  1. From your Iot hub in IoT Explorer, select View devices in this hub, then select your device from the list.

  2. On the left menu for your device, select Telemetry.

  3. Confirm that Use built-in event hub is set to Yes and then select Start.

  4. View the telemetry as the device sends messages to the cloud.

    Screenshot of device telemetry in IoT Explorer

  5. Select Stop to end receiving events.

To read telemetry sent by individual device components, you can use the plug and play features in IoT Explorer. For example, the temperature controller in this quickstart has two thermostats: thermostat1 and thermostat2. To see the temperature reported by thermostat1:

  1. On your device in IoT Explorer, select IoT Plug and Play components from the left menu. Then select thermostat1 from the list of components.

  2. On the thermostat1 component pane, select Telemetry from the top menu.

  3. On the Telemetry pane, follow the same steps that you did previously. Make sure that Use built-in event hub is set to Yes and then select Start.

To view device telemetry with Azure CLI:

  1. Run the az iot hub monitor-events command to monitor events sent from the simulated device to your IoT hub. Use the names that you created previously in Azure IoT for your device and IoT hub.

    az iot hub monitor-events --output table --device-id mydevice --hub-name {YourIoTHubName}
    
  2. View the connection details and telemetry output in the console.

    Starting event monitor, filtering on device: mydevice, use ctrl-c to stop...
    event:
      component: thermostat1
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 29
    
    event:
      component: thermostat2
      interface: dtmi:com:example:TemperatureController;2
      module: ''
      origin: mydevice
      payload:
        temperature: 48
    

Clean up resources

If you no longer need the Azure resources created in this quickstart, you can use the Azure CLI to delete them.

Important

Deleting a resource group is irreversible. The resource group and all the resources contained in it are permanently deleted. Make sure that you do not accidentally delete the wrong resource group or resources.

To delete a resource group by name:

  1. Run the az group delete command. This command removes the resource group, the IoT Hub, and the device registration you created.

    az group delete --name MyResourceGroup
    
  2. Run the az group list command to confirm the resource group is deleted.

    az group list
    

Next steps

In this quickstart, you learned a basic Azure IoT application workflow for securely connecting a device to the cloud and sending device-to-cloud telemetry. You used Azure CLI to create an Azure IoT hub and a device instance. Then you used an Azure IoT device SDK to create a simulated device, connect it to the hub, and send telemetry. You also used Azure portal to monitor telemetry.

As a next step, explore the following articles to learn more about building device solutions with Azure IoT.