Skip to content

Commit acc0b7b

Browse files
Merge pull request #191185 from kgremban/mar9-hubquickstart1
Review hub quickstarts -- part 1 (replacement pr)
2 parents 30abd8d + 8db89bb commit acc0b7b

File tree

6 files changed

+110
-112
lines changed

6 files changed

+110
-112
lines changed

articles/iot-hub/quickstart-control-device.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: iot-hub
77
services: iot-hub
88
ms.topic: quickstart
99
ms.custom: [mvc, mqtt, "Role: Cloud Development", devx-track-azurecli, mode-other]
10-
ms.date: 07/26/2021
10+
ms.date: 02/25/2022
1111
zone_pivot_groups: iot-hub-set1
1212
#Customer intent: As a developer new to IoT Hub, I need to see how to use a service application to control a device connected to the hub.
1313
---

articles/iot-hub/quickstart-send-telemetry-cli.md

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,38 @@ ms.topic: quickstart
66
ms.custom: [iot-send-telemetry-cli, iot-p0-scenario, "Role: Cloud Development", devx-track-azurecli, mode-api]
77
ms.author: timlt
88
author: timlt
9-
ms.date: 03/08/2022
9+
ms.date: 02/23/2022
1010
---
1111

1212
# Quickstart: Send telemetry from a device to an IoT hub and monitor it with the Azure CLI
1313

1414
IoT Hub is an Azure service that enables you to ingest high volumes of telemetry from your IoT devices into the cloud for storage or processing. In this quickstart, you use the Azure CLI to create an IoT Hub and a simulated device, send device telemetry to the hub, and send a cloud-to-device message. You also use the Azure portal to visualize device metrics. This is a basic workflow for developers who use the CLI to interact with an IoT Hub application.
1515

1616
## Prerequisites
17+
1718
- If you don't have an Azure subscription, [create one for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
18-
- Azure CLI. You can run all commands in this quickstart using the Azure Cloud Shell, an interactive CLI shell that runs in your browser. If you use the Cloud Shell, you don't need to install anything. If you prefer to use the CLI locally, this quickstart requires Azure CLI version 2.0.76 or later. Run az --version to find the version. To install or upgrade, see [Install Azure CLI]( /cli/azure/install-azure-cli).
19+
- Azure CLI. You can run all commands in this quickstart using the Azure Cloud Shell, an interactive CLI shell that runs in your browser. If you use the Cloud Shell, you don't need to install anything. If you prefer to use the CLI locally, this quickstart requires Azure CLI version 2.0.76 or later. Run `az --version` to find the version. To install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
1920

2021
## Sign in to the Azure portal
21-
Sign in to the Azure portal at https://portal.azure.com.
2222

23-
Regardless whether you run the CLI locally or in the Cloud Shell, keep the portal open in your browser. You use it later in this quickstart.
23+
Sign in to the [Azure portal](https://portal.azure.com).
24+
25+
Regardless of whether you run the CLI locally or in the Cloud Shell, keep the portal open in your browser. You use it later in this quickstart.
2426

2527
## Launch the Cloud Shell
28+
2629
In this section, you launch an instance of the Azure Cloud Shell. If you use the CLI locally, skip to the section [Prepare two CLI sessions](#prepare-two-cli-sessions).
2730

2831
To launch the Cloud Shell:
2932

30-
1. Select the **Cloud Shell** button on the top-right menu bar in the Azure portal.
33+
1. Select the **Cloud Shell** button on the top-right menu bar in the Azure portal.
3134

3235
![Azure portal Cloud Shell button](media/quickstart-send-telemetry-cli/cloud-shell-button.png)
3336

3437
> [!NOTE]
35-
> If this is the first time you've used the Cloud Shell, it prompts you to create storage, which is required to use the Cloud Shell. Select a subscription to create a storage account and Microsoft Azure Files share.
38+
> If this is the first time you've used the Cloud Shell, it prompts you to create storage, which is required to use the Cloud Shell. Select a subscription to create a storage account and Microsoft Azure Files share.
3639
37-
2. Select your preferred CLI environment in the **Select environment** dropdown. This quickstart uses the **Bash** environment. All the following CLI commands work in the PowerShell environment too.
40+
2. Select your preferred CLI environment in the **Select environment** dropdown. This quickstart uses the **Bash** environment. All the following CLI commands work in the PowerShell environment too.
3841

3942
![Select CLI environment](media/quickstart-send-telemetry-cli/cloud-shell-environment.png)
4043

@@ -44,147 +47,159 @@ In this section, you prepare two Azure CLI sessions. If you're using the Cloud S
4447

4548
Azure CLI requires you to be logged into your Azure account. All communication between your Azure CLI shell session and your IoT hub is authenticated and encrypted. As a result, this quickstart does not need additional authentication that you'd use with a real device, such as a connection string.
4649

47-
* Run the [az extension add](/cli/azure/extension#az_extension_add) command to add the Microsoft Azure IoT Extension for Azure CLI to your CLI shell. The IOT Extension adds IoT Hub, IoT Edge, and IoT Device Provisioning Service (DPS) specific commands to Azure CLI.
50+
- Run the [az extension add](/cli/azure/extension#az_extension_add) command to add the Microsoft Azure IoT Extension for Azure CLI to your CLI shell. The IOT Extension adds IoT Hub, IoT Edge, and IoT Device Provisioning Service (DPS) specific commands to Azure CLI.
4851

4952
```azurecli
5053
az extension add --name azure-iot
5154
```
52-
53-
After you install the Azure IOT extension, you don't need to install it again in any Cloud Shell session.
55+
56+
After you install the Azure IOT extension, you don't need to install it again in any Cloud Shell session.
5457

5558
[!INCLUDE [iot-hub-cli-version-info](../../includes/iot-hub-cli-version-info.md)]
5659

57-
* Open a second CLI session. If you're using the Cloud Shell, select **Open new session**. If you're using the CLI locally, open a second instance.
60+
- Open a second CLI session. If you're using the Cloud Shell, select **Open new session**. If you're using the CLI locally, open a second instance.
5861

5962
>[!div class="mx-imgBorder"]
6063
>![Open new Cloud Shell session](media/quickstart-send-telemetry-cli/cloud-shell-new-session.png)
6164
62-
## Create an IoT Hub
63-
In this section, you use the Azure CLI to create a resource group and an IoT Hub. 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 the devices.
65+
## Create an IoT hub
66+
67+
In this section, you use the Azure CLI to create a resource group and an IoT hub. 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 the devices.
6468

6569
> [!TIP]
66-
> Optionally, you can create an Azure resource group, an IoT Hub, and other resources by using the [Azure portal](iot-hub-create-through-portal.md), [Visual Studio Code](iot-hub-create-use-iot-toolkit.md), or other programmatic methods.
70+
> Optionally, you can create an Azure resource group, an IoT hub, and other resources by using the [Azure portal](iot-hub-create-through-portal.md), [Visual Studio Code](iot-hub-create-use-iot-toolkit.md), or other programmatic methods.
6771
68-
1. Run the [az group create](/cli/azure/group#az_group_create) command to create a resource group. The following command creates a resource group named *MyResourceGroup* in the *eastus* location.
72+
1. Run the [az group create](/cli/azure/group#az_group_create) command to create a resource group. The following command creates a resource group named *MyResourceGroup* in the *eastus* location.
6973

7074
```azurecli
7175
az group create --name MyResourceGroup --location eastus
7276
```
7377
74-
1. Run the [az iot hub create](/cli/azure/iot/hub#az_iot_hub_create) command to create an IoT hub. It might take a few minutes to create an IoT hub.
78+
1. Run the [az iot hub create](/cli/azure/iot/hub#az_iot_hub_create) command to create an IoT hub. It might take a few minutes to create an IoT hub.
7579
76-
*YourIotHubName*. Replace this placeholder name and the curly brackets with the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. This placeholder is used in the rest of this quickstart to represent your IoT hub name.
80+
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub. An IoT hub name must be globally unique in Azure. This placeholder is used in the rest of this quickstart to represent your IoT hub name.
7781
7882
```azurecli
7983
az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
8084
```
8185
8286
## Create and monitor a device
87+
8388
In this section, you create a simulated device in the first CLI session. The simulated device sends device telemetry to your IoT hub. In the second CLI session, you monitor events and telemetry, and send a cloud-to-device message to the simulated device.
8489
8590
To create and start a simulated device:
86-
1. Run the [az iot hub device-identity create](/cli/azure/iot/hub/device-identity#az_iot_hub_device_identity_create) command in the first CLI session. This creates the simulated device identity.
8791
88-
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
92+
1. Run the [az iot hub device-identity create](/cli/azure/iot/hub/device-identity#az_iot_hub_device_identity_create) command in the first CLI session. This creates the simulated device identity.
8993
90-
*simDevice*. You can use this name directly for the simulated device in the rest of this quickstart. Optionally, use a different name.
94+
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
95+
96+
*simDevice*. You can use this name directly for the simulated device in the rest of this quickstart. Optionally, use a different name.
9197
9298
```azurecli
9399
az iot hub device-identity create --device-id simDevice --hub-name {YourIoTHubName}
94100
```
95101
96102
1. Run the [az iot device simulate](/cli/azure/iot/device#az_iot_device_simulate) command in the first CLI session. This starts the simulated device. The device sends telemetry to your IoT hub and receives messages from it.
97103
98-
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
104+
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
99105
100106
```azurecli
101107
az iot device simulate -d simDevice -n {YourIoTHubName}
102108
```
103109
104110
To monitor a device:
111+
105112
1. In the second CLI session, run the [az iot hub monitor-events](/cli/azure/iot/hub#az_iot_hub_monitor_events) command. This starts monitoring the simulated device. The output shows telemetry that the simulated device sends to the IoT hub.
106113
107-
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
114+
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
108115
109116
```azurecli
110117
az iot hub monitor-events --output table --hub-name {YourIoTHubName}
111118
```
112119
113120
![Cloud Shell monitor events](media/quickstart-send-telemetry-cli/cloud-shell-monitor.png)
114121
115-
1. After you monitor the simulated device in the second CLI session, press Ctrl+C to stop monitoring.
122+
1. After you monitor the simulated device in the second CLI session, press Ctrl+C to stop monitoring.
116123
117124
## Use the CLI to send a message
125+
118126
In this section, you use the second CLI session to send a message to the simulated device.
119127
120128
1. In the first CLI session, confirm that the simulated device is running. If the device has stopped, run the following command to start it:
121129
122-
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
130+
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
123131
124132
```azurecli
125133
az iot device simulate -d simDevice -n {YourIoTHubName}
126134
```
127135
128136
1. In the second CLI session, run the [az iot device c2d-message send](/cli/azure/iot/device/c2d-message#az_iot_device_c2d-message-send) command. This sends a cloud-to-device message from your IoT hub to the simulated device. The message includes a string and two key-value pairs.
129137
130-
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
138+
*YourIotHubName*. Replace this placeholder below with the name you chose for your IoT hub.
131139
132140
```azurecli
133141
az iot device c2d-message send -d simDevice --data "Hello World" --props "key0=value0;key1=value1" -n {YourIoTHubName}
134142
```
135-
Optionally, you can send cloud-to-device messages by using the Azure portal. To do this, browse to the overview page for your IoT Hub, select **IoT Devices**, select the simulated device, and select **Message to Device**.
136143
137-
1. In the first CLI session, confirm that the simulated device received the message.
144+
Optionally, you can send cloud-to-device messages by using the Azure portal. To do this, browse to the overview page for your IoT Hub, select **IoT Devices**, select the simulated device, and select **Message to Device**.
145+
146+
1. In the first CLI session, confirm that the simulated device received the message.
138147
139148
![Cloud Shell cloud-to-device message](media/quickstart-send-telemetry-cli/cloud-shell-receive-message.png)
140149
141150
1. After you view the message, close the second CLI session. Keep the first CLI session open. You use it to clean up resources in a later step.
142151
143152
## View messaging metrics in the portal
144-
The Azure portal enables you to manage all aspects of your IoT Hub and devices. In a typical IoT Hub application that ingests telemetry from devices, you might want to monitor devices or view metrics on device telemetry.
153+
154+
The Azure portal enables you to manage all aspects of your IoT hub and devices. In a typical IoT Hub application that ingests telemetry from devices, you might want to monitor devices or view metrics on device telemetry.
145155
146156
To visualize messaging metrics in the Azure portal:
147-
1. In the left navigation menu on the portal, select **All Resources**. This lists all resources in your subscription, including the IoT hub you created.
157+
158+
1. In the left navigation menu on the portal, select **All Resources**. This lists all resources in your subscription, including the IoT hub you created.
148159
149160
1. Select the link on the IoT hub you created. The portal displays the overview page for the hub.
150161
151-
1. Select **Metrics** in the left pane of your IoT Hub.
162+
1. Select **Metrics** in the left pane of your IoT Hub.
152163
153164
![IoT Hub messaging metrics](media/quickstart-send-telemetry-cli/iot-hub-portal-metrics.png)
154165
155-
1. Enter your IoT hub name in **Scope**.
166+
1. In the **Scope** field, enter your IoT hub name.
156167
157-
2. Select *Iot Hub Standard Metrics* in **Metric Namespace**.
168+
1. In the **Metric Namespace** field, select *Iot Hub Standard Metrics*.
158169
159-
3. Select *Total number of messages used* in **Metric**.
170+
1. In the **Metric** field, select *Total number of messages used*.
160171
161-
4. Hover your mouse pointer over the area of the timeline in which your device sent messages. The total number of messages at a point in time appears in the lower left corner of the timeline.
172+
1. Hover your mouse pointer over the area of the timeline in which your device sent messages. The total number of messages at a point in time appears in the lower left corner of the timeline.
162173
163174
![View Azure IoT Hub metrics](media/quickstart-send-telemetry-cli/iot-hub-portal-view-metrics.png)
164175
165-
5. Optionally, use the **Metric** dropdown to display other metrics on your simulated device. For example, *C2d message deliveries completed* or *Total devices (preview)*.
176+
1. Optionally, use the **Metric** dropdown to display other metrics on your simulated device. For example, *C2d message deliveries completed* or *Total devices (preview)*.
166177
167178
## Clean up resources
179+
168180
If you no longer need the Azure resources created in this quickstart, you can use the Azure CLI to delete them.
169181
170-
If you continue to the next recommended article, you can keep the resources you've already created and reuse them.
182+
If you continue to the next recommended article, you can keep the resources you've already created and reuse them.
171183
172184
> [!IMPORTANT]
173-
> 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.
185+
> 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.
174186
175187
To delete a resource group by name:
188+
176189
1. Run the [az group delete](/cli/azure/group#az_group_delete) command. This removes the resource group, the IoT Hub, and the device registration you created.
177190
178191
```azurecli
179192
az group delete --name MyResourceGroup
180193
```
194+
181195
1. Run the [az group list](/cli/azure/group#az_group_list) command to confirm the resource group is deleted.
182196
183197
```azurecli
184198
az group list
185199
```
186200
187201
## Next steps
202+
188203
In this quickstart, you used the Azure CLI to create an IoT hub, create a simulated device, send telemetry, monitor telemetry, send a cloud-to-device message, and clean up resources. You used the Azure portal to visualize messaging metrics on your device.
189204
190205
If you are a device developer, the suggested next step is to see the telemetry quickstart that uses the Azure IoT Device SDK for C. Optionally, see one of the available Azure IoT Hub telemetry quickstart articles in your preferred language or SDK.

0 commit comments

Comments
 (0)