Skip to content

Commit 55823c9

Browse files
Merge pull request #191361 from kgremban/mar9-hubquickstart2
Review hub quickstarts -- direct method node, java, python
2 parents f3ff0d0 + 8a59e37 commit 55823c9

File tree

4 files changed

+114
-69
lines changed

4 files changed

+114
-69
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: kgremban
5+
ms.author: kgremban
6+
ms.service: iot-hub
7+
ms.topic: include
8+
ms.date: 03/10/2022
9+
---
10+
11+
## Create an IoT hub
12+
13+
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 the devices.
14+
15+
If you already have an IoT hub in your Azure subscription, you can skip this section.
16+
17+
To create an IoT hub and a resource group:
18+
19+
1. Launch your CLI app. To run the CLI commands in the rest of this quickstart, copy the command syntax, paste it into your CLI app, edit variable values, and press `Enter`.
20+
21+
- 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](https://shell.azure.com/bash) in a separate browser tab.
22+
- If you're using Azure CLI locally, start your CLI console app and sign in to Azure CLI.
23+
24+
1. Run [az extension add](/cli/azure/extension#az_extension_add) to install or upgrade the *azure-iot* extension to the current version.
25+
26+
```azurecli-interactive
27+
az extension add --upgrade --name azure-iot
28+
```
29+
30+
1. In your CLI app, 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.
31+
32+
>[!NOTE]
33+
> Optionally, you can set a different location. To see available locations, run `az account list-locations`.
34+
35+
```azurecli-interactive
36+
az group create --name MyResourceGroup --location eastus
37+
```
38+
39+
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.
40+
41+
*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.
42+
43+
```azurecli-interactive
44+
az iot hub create --resource-group MyResourceGroup --name {YourIoTHubName}
45+
```

includes/quickstart-control-device-java.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
---
2-
author: phlmea
3-
ms.author: philmea
2+
author: kgremban
3+
ms.author: kgremban
44
ms.service: iot-hub
55
services: iot-hub
66
ms.devlang: java
77
ms.topic: include
88
ms.custom: [mvc, seo-java-august2019, seo-java-september2019, mqtt, devx-track-java, devx-track-azurecli]
9-
ms.date: 06/21/2019
9+
ms.date: 03/10/2022
1010
---
1111

12-
This quickstart uses two Java applications: a simulated device application that responds to direct methods called from a back-end application and a service application that calls the direct method on the simulated device.
12+
This quickstart uses two Java applications:
13+
14+
* A simulated device application that responds to direct methods called from a back-end application.
15+
* A service application that calls the direct method on the simulated device.
1316

1417
## Prerequisites
1518

@@ -31,27 +34,23 @@ This quickstart uses two Java applications: a simulated device application that
3134
mvn --version
3235
```
3336
34-
* [A sample Java project](https://github.com/Azure-Samples/azure-iot-samples-java/archive/master.zip).
37+
* Clone or download the [Azure IoT Java samples](https://github.com/Azure-Samples/azure-iot-samples-java/) from GitHub.
3538
36-
* Port 8883 open in your firewall. The device sample in this quickstart uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../articles/iot-hub/iot-hub-mqtt-support.md#connecting-to-iot-hub).
39+
* Make sure that port 8883 open in your firewall. The device sample in this quickstart uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../articles/iot-hub/iot-hub-mqtt-support.md#connecting-to-iot-hub).
3740
3841
[!INCLUDE [azure-cli-prepare-your-environment.md](azure-cli-prepare-your-environment-no-header.md)]
3942
4043
[!INCLUDE [iot-hub-cli-version-info](iot-hub-cli-version-info.md)]
4144
42-
## Create an IoT hub
43-
44-
If you completed the previous [Quickstart: Send telemetry from a device to an IoT hub](../articles/iot-develop/quickstart-send-telemetry-iot-hub.md?pivots=programming-language-java), you can skip this step.
45-
46-
[!INCLUDE [iot-hub-include-create-hub](iot-hub-include-create-hub.md)]
45+
[!INCLUDE [iot-hub-include-create-hub](iot-hub-include-create-hub-quickstart.md)]
4746
4847
## Register a device
4948
50-
If you completed the previous [Quickstart: Send telemetry from a device to an IoT hub](../articles/iot-develop/quickstart-send-telemetry-iot-hub.md?pivots=programming-language-java), you can skip this step.
49+
A device must be registered with your IoT hub before it can connect. In this quickstart, you use the Azure Cloud Shell to create a device identity.
5150
52-
A device must be registered with your IoT hub before it can connect. In this quickstart, you use the Azure Cloud Shell to register a simulated device.
51+
If you already have a device registered in your IoT hub, you can skip this section.
5352
54-
1. Run the following command in Azure Cloud Shell to create the device identity.
53+
1. Run the [az iot hub device-identity create](/cli/azure/iot/hub/device-identity#az_iot_hub_device_identity_create) command in Azure Cloud Shell to create the device identity.
5554
5655
**YourIoTHubName**: Replace this placeholder below with the name you chose for your IoT hub.
5756
@@ -62,7 +61,7 @@ A device must be registered with your IoT hub before it can connect. In this qui
6261
--hub-name {YourIoTHubName} --device-id MyJavaDevice
6362
```
6463
65-
2. Run the following commands in Azure Cloud Shell to get the _device connection string_ for the device you just registered:
64+
2. Run the [az iot hub device-identity connection-string show](/cli/azure/iot/hub/device-identity/connection-string#az_iot_hub_device_identity_connection_string_show) command in Azure Cloud Shell to get the _device connection string_ for the device you just registered:
6665
6766
**YourIoTHubName**: Replace this placeholder below with the name you choose for your IoT hub.
6867
@@ -95,7 +94,7 @@ Make a note of the service connection string, which looks like:
9594

9695
You use this value later in the quickstart. This service connection string is different from the device connection string you noted in the previous step.
9796

98-
## Listen for direct method calls
97+
## Simulate a device
9998

10099
The simulated device application connects to a device-specific endpoint on your IoT hub, sends simulated telemetry, and listens for direct method calls from your hub. In this quickstart, the direct method call from the hub tells the device to change the interval at which it sends telemetry. The simulated device sends an acknowledgment back to your hub after it executes the direct method.
101100

includes/quickstart-control-device-node.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
---
2-
author: philmea
3-
ms.author: philmea
2+
author: kgremban
3+
ms.author: kgremban
44
ms.service: iot-hub
55
services: iot-hub
66
ms.devlang: nodejs
77
ms.topic: include
88
ms.custom: [mvc, seo-javascript-september2019, seo-javascript-october2019, mqtt, 'Role: Cloud Development', devx-track-js, devx-track-azurecli]
9-
ms.date: 06/21/2019
9+
ms.date: 03/09/2022
1010
---
1111

12-
This quickstart uses two Node.js applications: a simulated device application that responds to direct methods called from a back-end application and a back-end application that calls the direct methods on the simulated device.
12+
This quickstart uses two Node.js applications:
13+
14+
* A simulated device application that responds to direct methods called from a back-end application. To receive the direct method calls, this application connects to a device-specific endpoint on your IoT hub.
15+
* A back-end application that calls the direct methods on the simulated device. To call a direct method on a device, this application connects to a service-specific endpoint on your IoT hub.
1316

1417
## Prerequisites
1518

@@ -23,27 +26,23 @@ This quickstart uses two Node.js applications: a simulated device application th
2326
node --version
2427
```
2528
26-
* [A sample Node.js project](https://github.com/Azure-Samples/azure-iot-samples-node/archive/master.zip).
29+
* Clone or download the [Azure IoT Node.js samples](https://github.com/Azure-Samples/azure-iot-samples-node/) from GitHub.
2730
28-
* Port 8883 open in your firewall. The device sample in this quickstart uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../articles/iot-hub/iot-hub-mqtt-support.md#connecting-to-iot-hub).
31+
* Make sure that port 8883 is open in your firewall. The device sample in this quickstart uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../articles/iot-hub/iot-hub-mqtt-support.md#connecting-to-iot-hub).
2932
3033
[!INCLUDE [azure-cli-prepare-your-environment.md](azure-cli-prepare-your-environment-no-header.md)]
3134
3235
[!INCLUDE [iot-hub-cli-version-info](iot-hub-cli-version-info.md)]
3336
34-
## Create an IoT hub
35-
36-
If you completed the previous [Quickstart: Send telemetry from a device to an IoT hub](../articles/iot-develop/quickstart-send-telemetry-iot-hub.md?pivots=programming-language-nodejs), you can skip this step.
37-
38-
[!INCLUDE [iot-hub-include-create-hub](iot-hub-include-create-hub.md)]
37+
[!INCLUDE [iot-hub-include-create-hub](iot-hub-include-create-hub-quickstart.md)]
3938
4039
## Register a device
4140
42-
If you completed the previous [Quickstart: Send telemetry from a device to an IoT hub](../articles/iot-develop/quickstart-send-telemetry-iot-hub.md?pivots=programming-language-nodejs), you can skip this step.
41+
A device must be registered with your IoT hub before it can connect. In this quickstart, you use Azure CLI to create a device identity.
4342
44-
A device must be registered with your IoT hub before it can connect. In this quickstart, you use the Azure Cloud Shell to register a simulated device.
43+
If you already have a device registered in your IoT hub, you can skip this section.
4544
46-
1. Run the following command in Azure Cloud Shell to create the device identity.
45+
1. Run the [az iot hub device-identity create](/cli/azure/iot/hub/device-identity#az_iot_hub_device_identity_create) command in Azure Cloud Shell to create the device identity.
4746
4847
**YourIoTHubName**: Replace this placeholder below with the name you chose for your IoT hub.
4948
@@ -54,7 +53,7 @@ A device must be registered with your IoT hub before it can connect. In this qui
5453
--hub-name {YourIoTHubName} --device-id MyNodeDevice
5554
```
5655
57-
2. Run the following commands in Azure Cloud Shell to get the _device connection string_ for the device you just registered:
56+
2. Run the [az iot hub device-identity connection-string show](/cli/azure/iot/hub/device-identity/connection-string#az_iot_hub_device_identity_connection_string_show) command in Azure Cloud Shell to get the _device connection string_ for the device you just registered:
5857
5958
**YourIoTHubName**: Replace this placeholder below with the name you chose for your IoT hub.
6059
@@ -71,23 +70,24 @@ A device must be registered with your IoT hub before it can connect. In this qui
7170
7271
You use this value later in the quickstart.
7372
74-
3. You also need a _service connection string_ to enable the back-end application to connect to your IoT hub and retrieve the messages. The following command retrieves the service connection string for your IoT hub:
73+
## Retrieve the service connection string
7574
76-
**YourIoTHubName**: Replace this placeholder below with the name you chose for your IoT hub.
75+
You also need your IoT hub's _service connection string_ to enable the back-end application to connect to your IoT hub and retrieve the messages. The following command retrieves the service connection string for your IoT hub:
7776
78-
```azurecli-interactive
79-
az iot hub connection-string show \
80-
--policy-name service --name {YourIoTHubName} --output table
77+
**YourIoTHubName**: Replace this placeholder below with the name you chose for your IoT hub.
8178
82-
```
79+
```azurecli-interactive
80+
az iot hub connection-string show \
81+
--policy-name service --name {YourIoTHubName} --output table
82+
```
8383

84-
Make a note of the service connection string, which looks like:
84+
Make a note of the service connection string, which looks like:
8585

86-
`HostName={YourIoTHubName}.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey={YourSharedAccessKey}`
86+
`HostName={YourIoTHubName}.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey={YourSharedAccessKey}`
8787

88-
You use this value later in the quickstart. This service connection string is different from the device connection string you noted in the previous step.
88+
You use this value later in the quickstart. This service connection string is different from the device connection string you noted in the previous step.
8989

90-
## Listen for direct method calls
90+
## Simulate a device
9191

9292
The simulated device application connects to a device-specific endpoint on your IoT hub, sends simulated telemetry, and listens for direct method calls from your hub. In this quickstart, the direct method call from the hub tells the device to change the interval at which it sends telemetry. The simulated device sends an acknowledgment back to your hub after it executes the direct method.
9393

@@ -110,7 +110,7 @@ The simulated device application connects to a device-specific endpoint on your
110110
111111
## Call the direct method
112112
113-
The back-end application connects to a service-side endpoint on your IoT Hub. The application makes direct method calls to a device through your IoT hub and listens for acknowledgments. An IoT Hub back-end application typically runs in the cloud.
113+
The back-end application connects to a service-side endpoint on your IoT hub. The application makes direct method calls to a device through your IoT hub and listens for acknowledgments. An IoT Hub back-end application typically runs in the cloud.
114114
115115
1. In another local terminal window, navigate to the root folder of the sample Node.js project. Then navigate to the **iot-hub\Quickstarts\back-end-application** folder.
116116

0 commit comments

Comments
 (0)