Skip to content

Commit 954812c

Browse files
authored
Merge pull request #277785 from kgremban/jun10-hubdevice
New article - create, connect device
2 parents 4beb2fc + 85b8a41 commit 954812c

33 files changed

+223
-60
lines changed

articles/azure-maps/tutorial-iot-hub-maps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ To learn more about how to send device-to-cloud telemetry, and the other way aro
279279
[geofence JSON data file]: https://raw.githubusercontent.com/Azure-Samples/iothub-to-azure-maps-geofencing/master/src/Data/geofence.json?token=AKD25BYJYKDJBJ55PT62N4C5LRNN4
280280
[Plug and Play schema for geospatial data]: https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v1-preview/schemas/geospatial.md
281281
[Postman]: https://www.postman.com/
282-
[register a new device in the IoT hub]: ../iot-hub/iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub
282+
[register a new device in the IoT hub]: ../iot-hub/create-connect-device.md
283283
[rentalCarSimulation]: https://github.com/Azure-Samples/iothub-to-azure-maps-geofencing/tree/master/src/rentalCarSimulation
284284
[resource group]: ../azure-resource-manager/management/manage-resource-groups-portal.md#create-resource-groups
285285
[the root of the sample]: https://github.com/Azure-Samples/iothub-to-azure-maps-geofencing

articles/iot-hub/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@
235235
- name: Use a template from Azure PowerShell
236236
displayName: create IoT Hub, register device, message routing, delete IoT hub, Azure Resource Manager
237237
href: iot-hub-rm-template-powershell.md
238+
- name: Create and connect a device
239+
href: create-connect-device.md
238240
- name: Create message routes and endpoints
239241
items:
240242
- name: Azure portal

articles/iot-hub/authenticate-authorize-x509.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ A successful device connection to IoT Hub completes the authentication process a
101101

102102
## Revoke a device certificate
103103

104-
IoT Hub doesn't check certificate revocation lists from the certificate authority when authenticating devices with certificate-based authentication. If you have a device that needs to be blocked from connecting to IoT Hub because of a potentially compromised certificate, you should disable the device in the identity registry. For more information, see [Disable or delete a device in an IoT hub](./iot-hub-create-through-portal.md#disable-or-delete-a-device-in-an-iot-hub).
104+
IoT Hub doesn't check certificate revocation lists from the certificate authority when authenticating devices with certificate-based authentication. If you have a device that needs to be blocked from connecting to IoT Hub because of a potentially compromised certificate, you should disable the device in the identity registry. For more information, see [Disable or delete a device](./create-connect-device.md#disable-or-delete-a-device).
105105

106106
## Example scenario
107107

articles/iot-hub/c2d-messaging-dotnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You can find more information on cloud-to-device messages in [D2C and C2D Messag
4545

4646
* An IoT hub in your Azure subscription. If you don't have a hub yet, you can follow the steps in [Create an IoT hub](iot-hub-create-through-portal.md).
4747

48-
* A device registered in your IoT hub. If you haven't registered a device yet, register one in the [Azure portal](iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub).
48+
* A device registered in your IoT hub. If you don't have a device in your IoT hub, follow the steps in [Register a device](create-connect-device.md#register-a-device).
4949

5050
* This article uses sample code from the [Azure IoT SDK for C#](https://github.com/Azure/azure-iot-sdk-csharp).
5151

articles/iot-hub/c2d-messaging-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To learn more about cloud-to-device messages, see [Send cloud-to-device messages
4545

4646
* An IoT hub in your Azure subscription. If you don't have a hub yet, you can follow the steps in [Create an IoT hub](iot-hub-create-through-portal.md).
4747

48-
* A device registered in your IoT hub. If you haven't registered a device yet, register one in the [Azure portal](iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub).
48+
* A device registered in your IoT hub. If you don't have a device in your IoT hub, follow the steps in [Register a device](create-connect-device.md#register-a-device).
4949

5050
* This article uses sample code from the [Azure IoT SDK for Java](https://github.com/Azure/azure-iot-sdk-java).
5151

articles/iot-hub/c2d-messaging-node.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To learn more about cloud-to-device messages, see [Send cloud-to-device messages
4545

4646
* An IoT hub in your Azure subscription. If you don't have a hub yet, you can follow the steps in [Create an IoT hub](iot-hub-create-through-portal.md).
4747

48-
* A device registered in your IoT hub. If you haven't registered a device yet, register one in the [Azure portal](iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub).
48+
* A device registered in your IoT hub. If you don't have a device in your IoT hub, follow the steps in [Register a device](create-connect-device.md#register-a-device).
4949

5050
* This article uses sample code from the [Azure IoT SDK for Node.js](https://github.com/Azure/azure-iot-sdk-node).
5151

articles/iot-hub/c2d-messaging-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To learn more about cloud-to-device messages, see [Send cloud-to-device messages
4343

4444
* An IoT hub. Create one with the [CLI](iot-hub-create-using-cli.md) or the [Azure portal](iot-hub-create-through-portal.md).
4545

46-
* A registered device. Register one in the [Azure portal](iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub).
46+
* A device registered in your IoT hub. If you don't have a device in your IoT hub, follow the steps in [Register a device](create-connect-device.md#register-a-device).
4747

4848
* [Python version 3.7 or later](https://www.python.org/downloads/) is recommended. Make sure to use the 32-bit or 64-bit installation as required by your setup. When prompted during the installation, make sure to add Python to your platform-specific environment variable.
4949

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
title: Register and connect an IoT device
3+
titleSuffix: Azure IoT Hub
4+
description: How to create, manage, and delete Azure IoT devices and how to retrieve the device connection string.
5+
author: kgremban
6+
7+
ms.author: kgremban
8+
ms.service: iot-hub
9+
ms.topic: how-to
10+
ms.date: 06/19/2024
11+
---
12+
13+
# Create and manage device identities
14+
15+
Create a device identity for your device to connect to Azure IoT Hub. This article introduces key tasks for managing a device identity including registering the device, collecting its connection information, and then deleting or disabling a device at the end of its lifecycle.
16+
17+
## Prerequisites
18+
19+
* An IoT hub in your subscription. If you don't have an IoT hub, follow the steps in [create an IoT hub](./iot-hub-create-through-portal.md).
20+
21+
* Depending on which tool you use, either have access to the [Azure portal](https://portal.azure.com) or [install the Azure CLI](/cli/azure/install-azure-cli).
22+
23+
* If your IoT hub is managed with role-based access control (RBAC), then you need **Read/Write/Delete Device/Module** permissions for the steps in this article. Those permissions are included in [IoT Hub Registry Contributor](../role-based-access-control/built-in-roles/internet-of-things.md#iot-hub-registry-contributor) role.
24+
25+
## Register a device
26+
27+
In this section, you create a device identity in the [identity registry in your IoT hub](./iot-hub-devguide-identity-registry.md). A device can't connect to a hub unless it has a device identity.
28+
29+
The IoT Hub identity registry only stores device identities to enable secure access to the IoT hub. It stores device IDs and keys to use as security credentials, and an enabled/disabled flag that you can use to disable access for an individual device.
30+
31+
When you register a device, you choose its authentication method. IoT Hub supports three methods for device authentication:
32+
33+
* **Symmetric key** - *This option is easiest for quickstart scenarios.*
34+
35+
When you register a device, you can provide keys or IoT Hub will generate keys for you. Both the device and the IoT hub have a copy of the symmetric key that can be compared when the device connects.
36+
37+
* **X.509 self-signed**
38+
39+
If your device has a self-signed X.509 certificate, then you need to give IoT Hub a version of the certificate for authentication. When you register a device, you upload a certificate *thumbprint*, which is a hash of the device's X.509 certificate. When the device connects, it presents its certificate and the IoT hub can validate it against the hash it knows. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md).
40+
41+
* **X.509 CA signed** - *This option is recommended for production scenarios.*
42+
43+
If your device has a CA-signed X.509 certificate, then you upload a root or intermediate certificate authority (CA) certificate in the signing chain to IoT Hub before you register the device. The device has an X.509 certificate with the verified X.509 CA in its certificate chain of trust. When the device connects, it presents its full certificate chain and the IoT hub can validate it because it knows the X.509 CA. Multiple devices can authenticate against the same verified X.509 CA. For more information, see [Authenticate identities with X.509 certificates](./authenticate-authorize-x509.md).
44+
45+
### Prepare certificates
46+
47+
If you're using either of the X.509 certificate authentication methods, make sure your certificates are ready before registering a device:
48+
49+
* For CA-signed certificates, the tutorial [Create and upload certificates for testing](./tutorial-x509-test-certs.md) provides a good introduction for how to create CA-signed certificates and upload them to IoT Hub. After completing that tutorial, you're ready to register a device with **X.509 CA signed** authentication.
50+
51+
* For self-signed certificates, you need two device certificates (a primary and a secondary certificate) on the device and thumbprints for both to upload to IoT Hub. One way to retrieve the thumbprint from a certificate is with the following OpenSSL command:
52+
53+
```bash
54+
openssl x509 -in <certificate filename>.pem -text -fingerprint
55+
```
56+
57+
### Add a device
58+
59+
Create a device identity in your IoT hub.
60+
61+
### [Azure portal](#tab/portal)
62+
63+
1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
64+
65+
1. Select **Device management** > **Devices**.
66+
67+
1. Select **Add Device** to add a device in your IoT hub.
68+
69+
:::image type="content" source="./media/create-connect-device/add-device.png" alt-text="Screenshot that shows adding a new device in the Azure portal." lightbox="./media/create-connect-device/add-device.png":::
70+
71+
1. In **Create a device**, provide the information for your new device identity:
72+
73+
| Parameter | Dependent parameter | Value |
74+
| -- | -- | -- |
75+
| **Device ID** | | Provide a name for your new device. |
76+
| **Authentication type** | | Select either **Symmetric key**, **X.509 self-signed**, or **X.509 CA signed**. |
77+
| | **Auto-generate keys** | For **Symmetric key** authentication, check this box to have IoT Hub generate keys for your device. Or, uncheck this box and provide primary and secondary keys for your device. |
78+
| | **Primary thumbprint** and **Secondary thumbprint** | For **X.509 self-signed** authentication, provide the thumbprint hash from the device's primary and secondary certificates. |
79+
80+
[!INCLUDE [iot-hub-pii-note-naming-device](../../includes/iot-hub-pii-note-naming-device.md)]
81+
82+
1. Select **Save**.
83+
84+
### [Azure CLI](#tab/cli)
85+
86+
Use the [az iot hub device-identity create](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-create) command to register a device.
87+
88+
The following table describes common parameters used with this command.
89+
90+
| Parameter | Dependent parameter | Value |
91+
| -- | -- | -- |
92+
| `--device-id`, `-d` | | Provide a name for your new device. |
93+
| `--hub-name`, `-h` | | IoT hub name or hostname. |
94+
| `--auth-method`, `--am` | | Either `shared_private_key`, `x509_ca`, or `x509_thumbprint` |
95+
| | `--primary-key`, `--pk` and `--secondary-key`, `--sk` | Use with `shared_private_key` authentication if you want to provide the primary and secondary keys for your device. Omit if you want IoT Hub to generate the keys. |
96+
| | `--primary-thumbprint`, `--ptp` and `--secondary-thumbprint`, `--stp` | Use with `x509_thumbprint` authentication to provide the primary and secondary certificate thumbprints for your device. Omit if you want IoT Hub to generate a self-signed certificate and use its thumbprint. |
97+
98+
[!INCLUDE [iot-hub-pii-note-naming-device](../../includes/iot-hub-pii-note-naming-device.md)]
99+
100+
---
101+
102+
## Retrieve device connection string
103+
104+
For samples and test scenarios, the most common connection method is to use symmetric key authentication and connect with a *device connection string*. A device connection string contains the name of the IoT hub, the name of the device, and the device's authentication information.
105+
106+
For information about other methods for connecting devices, particularly for X.509 authentication, refer to the [Azure IoT Hub device SDKs](./iot-hub-devguide-sdks.md#azure-iot-hub-device-sdks).
107+
108+
Use the following steps to retrieve a device connection string.
109+
110+
### [Azure portal](#tab/portal)
111+
112+
The Azure portal provides device connection strings only for devices that use symmetric key authentication.
113+
114+
1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
115+
116+
1. Select **Device management** > **Devices**.
117+
118+
1. Select your device from the list in the **Devices** pane.
119+
120+
1. Copy the value of **Primary connection string**.
121+
122+
:::image type="content" source="./media/create-connect-device/copy-connection-string.png" alt-text="Screenshot that shows copying the value of the primary connection string from the Azure portal.":::
123+
124+
By default, the keys and connection strings are masked because they're sensitive information. If you click the eye icon, they're revealed. It's not necessary to reveal them to copy them with the copy button.
125+
126+
### [Azure CLI](#tab/cli)
127+
128+
Use the [az iot hub device-identity connection-string show](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-connection-string-show) command to retrieve a device's connection string. For example:
129+
130+
```bash
131+
az iot hub device-identity connection-string show --device-id <DEVICE_NAME> --hub-name <IOT_HUB_NAME>
132+
```
133+
134+
---
135+
136+
Devices with symmetric key authentication have a device connection string with the following pattern:
137+
138+
`HostName=<IOT_HUB_NAME>;DeviceId=<DEVICE_NAME>;SharedAccessKey=<PRIMARY_OR_SECONDARY_KEY>`
139+
140+
Devices with X.509 authentication, either self-signed or CA-signed, usually don't use device connection strings for authentication. When they do, their connection strings take the following pattern:
141+
142+
`HostName=<IOT_HUB_NAME>;DeviceId=<DEVICE_NAME>;x509=true`
143+
144+
## Disable or delete a device
145+
146+
If you want to keep a device in your IoT hub's identity registry, but want to prevent it from connecting then you can change its status to *disabled.*
147+
148+
### [Azure portal](#tab/portal)
149+
150+
1. In the [Azure portal](https://portal.azure.com), navigate to your IoT hub.
151+
152+
1. Select **Device management** > **Devices**.
153+
154+
1. Select your device from the list in the **Devices** pane.
155+
156+
1. On the device details page, you can disable or delete the device registration.
157+
158+
* To prevent a device from connecting, set the **Enable connection to IoT Hub** parameter to **Disable**.
159+
160+
* To completely remove a device from your IoT hub's identity registry, select **Delete**.
161+
162+
### [Azure CLI](#tab/cli)
163+
164+
To disable a device, use the [az iot hub device-identity update](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-update) command and change the `status` of the device. For example:
165+
166+
```bash
167+
az iot hub device-identity update --device-id <DEVICE_NAME> --hub-name <IOT_HUB_NAME> --set status=disabled
168+
```
169+
170+
To delete a device, use the [az iot hub device-identity delete](/cli/azure/iot/hub/device-identity#az-iot-hub-device-identity-delete) command. For example:
171+
172+
```bash
173+
az iot hub device-identity delete --device-id <DEVICE_NAME> --hub-name <IOT_HUB_NAME>
174+
```
175+
176+
---
177+
178+
## Other tools for managing device identities
179+
180+
You can use other tools or interfaces to manage the IoT Hub identity registry, including:
181+
182+
* **PowerShell commands**: Refer to the [Az.IotHub](/powershell/module/az.iothub/) command set to learn how to manage device identities.
183+
184+
* **Visual Studio Code**: The [Azure IoT Hub extension for Visual Studio Code](./reference-iot-hub-extension.md) includes identity registry capabilities.
185+
186+
* **REST API**: Refer to the [IoT Hub Service APIs](/rest/api/iothub/service/devices) to learn how to manage device identities.

articles/iot-hub/device-management-dotnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ This article shows you how to create:
3030

3131
* An IoT hub. Create one with the [CLI](iot-hub-create-using-cli.md) or the [Azure portal](iot-hub-create-through-portal.md).
3232

33-
* A registered device. Register one in the [Azure portal](iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub).
33+
* A device registered in your IoT hub. If you don't have a device in your IoT hub, follow the steps in [Register a device](create-connect-device.md#register-a-device).
3434

3535
* Make sure that port 8883 is open in your firewall. The device sample in this article 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)](../iot/iot-mqtt-connect-to-iot-hub.md#connecting-to-iot-hub).
3636

articles/iot-hub/device-management-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This article shows you how to create:
3131

3232
* An IoT hub. Create one with the [CLI](iot-hub-create-using-cli.md) or the [Azure portal](iot-hub-create-through-portal.md).
3333

34-
* A registered device. Register one in the [Azure portal](iot-hub-create-through-portal.md#register-a-new-device-in-the-iot-hub).
34+
* A device registered in your IoT hub. If you don't have a device in your IoT hub, follow the steps in [Register a device](create-connect-device.md#register-a-device).
3535

3636
* [Java SE Development Kit 8](/java/azure/jdk/). Make sure you select **Java 8** under **Long-term support** to get to downloads for JDK 8.
3737

0 commit comments

Comments
 (0)