Skip to content

Commit dfe159d

Browse files
Merge pull request #292660 from gsteve88/add-cert-device-management
Added certificate steps to device section
2 parents 5c611af + cf7b88c commit dfe159d

5 files changed

+73
-23
lines changed

articles/iot-hub/how-to-device-management.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: lizross
88
ms.service: azure-iot-hub
99
ms.devlang: csharp
1010
ms.topic: how-to
11-
ms.date: 11/25/2024
11+
ms.date: 1/6/2025
1212
zone_pivot_groups: iot-hub-howto-c2d-1
1313
---
1414

includes/iot-hub-howto-device-management-dotnet.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: iot-hub
88
ms.devlang: csharp
99
ms.topic: include
10-
ms.date: 11/25/2024
10+
ms.date: 1/6/2025
1111
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1212
---
1313

@@ -21,9 +21,7 @@ This article describes how to use the [Azure IoT SDK for .NET](https://github.co
2121

2222
This section describes how to use device application code to create a direct method callback listener.
2323

24-
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
25-
26-
### Required device NuGet package
24+
### Required device NuGet packages
2725

2826
Device client applications written in C# require the **Microsoft.Azure.Devices.Client** NuGet package.
2927

@@ -34,7 +32,16 @@ using Microsoft.Azure.Devices.Client;
3432
using Microsoft.Azure.Devices.Shared;
3533
```
3634

37-
### Connect to a device
35+
### Connect a device to IoT Hub
36+
37+
A device app can authenticate with IoT Hub using the following methods:
38+
39+
* Shared access key
40+
* X.509 certificate
41+
42+
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
43+
44+
#### Authenticate using a shared access key
3845

3946
The [DeviceClient](/dotnet/api/microsoft.azure.devices.client.deviceclient) class exposes all the methods required to interact with device messages from the device.
4047

@@ -59,6 +66,10 @@ deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString,
5966
TransportType.Mqtt);
6067
```
6168

69+
#### Authenticate using an X.509 certificate
70+
71+
[!INCLUDE [iot-hub-howto-auth-device-cert-dotnet](iot-hub-howto-auth-device-cert-dotnet.md)]
72+
6273
### Create a direct method callback listener
6374

6475
Use [SetMethodHandlerAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.setmethodhandlerasync) to initialize a direct method callback listener. The listener is associated with a method name keyword, such as "reboot". The method name can be used in an IoT Hub or backend application to trigger the callback method on the device.

includes/iot-hub-howto-device-management-java.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: iot-hub
88
ms.devlang: csharp
99
ms.topic: include
10-
ms.date: 11/25/2024
10+
ms.date: 1/6/2025
1111
ms.custom: amqp, mqtt, devx-track-java, devx-track-extended-java
1212
---
1313

@@ -21,9 +21,11 @@ This article describes how to use the [Azure IoT SDK for Java](https://github.co
2121

2222
This section describes how to use device application code to create a direct method callback listener.
2323

24+
The [DeviceClient](/java/api/com.microsoft.azure.sdk.iot.device.deviceclient) class exposes all the methods you require to interact with direct methods on the device.
25+
2426
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
2527

26-
### Device import statement
28+
### Device import statements
2729

2830
Use the following device import statements to access the Azure IoT SDK for Java.
2931

@@ -37,9 +39,16 @@ import com.microsoft.azure.sdk.iot.device.transport.IotHubConnectionStatus;
3739
import com.microsoft.azure.sdk.iot.device.twin.SubscriptionAcknowledgedCallback;
3840
```
3941

40-
### Connect to a device
42+
### Connect a device to IoT Hub
4143

42-
The [DeviceClient](/java/api/com.microsoft.azure.sdk.iot.device.deviceclient) class exposes all the methods you require to interact with direct methods on the device.
44+
A device app can authenticate with IoT Hub using the following methods:
45+
46+
* Shared access key
47+
* X.509 certificate
48+
49+
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
50+
51+
#### Authenticate using a shared access key
4352

4453
To connect to a device:
4554

@@ -62,6 +71,10 @@ To connect to a device:
6271
client.open(true);
6372
```
6473

74+
#### Authenticate using an X.509 certificate
75+
76+
[!INCLUDE [iot-hub-howto-auth-device-cert-java](iot-hub-howto-auth-device-cert-java.md)]
77+
6578
### Create a direct method callback listener
6679

6780
Use [subscribeToMethods](https://azure.github.io/azure-iot-sdk-java/master/device/com/microsoft/azure/sdk/iot/device/InternalClient.html#subscribeToMethods-com.microsoft.azure.sdk.iot.device.twin.MethodCallback-java.lang.Object-int-) to initialize a direct method callback listener. `subscribeToMethods` listens for incoming direct methods until the connection is terminated. The method name and payload is received for each direct method call.
@@ -92,7 +105,7 @@ The Azure IoT SDK for Java includes a working sample to test the device app conc
92105

93106
This section describes how to initiate a remote reboot on a device using a direct method.
94107

95-
The `ServiceClient` [DeviceMethod](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicemethod) class contains methods that services can use to access device twins.
108+
The `ServiceClient` [DeviceMethod](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicemethod) class contains methods that services can use to access direct methods.
96109

97110
### Service import statements
98111

includes/iot-hub-howto-device-management-node.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: iot-hub
88
ms.devlang: csharp
99
ms.topic: include
10-
ms.date: 11/25/2024
10+
ms.date: 1/6/2025
1111
ms.custom: mqtt, devx-track-js
1212
---
1313

@@ -21,15 +21,30 @@ This article describes how to use the [Azure IoT SDK for Node.js](https://github
2121

2222
This section describes how to use device application code to create a direct method callback.
2323

24-
### Install SDK packages
24+
### Install SDK package
2525

2626
The [azure-iot-device](/javascript/api/azure-iot-device) package contains objects that interface with IoT devices. Run this command to install the **azure-iot-device** device SDK on your development machine:
2727

2828
```cmd/sh
2929
npm install azure-iot-device --save
3030
```
3131

32-
### Choose a transport protocol
32+
### Connect a device to IoT Hub
33+
34+
A device app can authenticate with IoT Hub using the following methods:
35+
36+
* X.509 certificate
37+
* Shared access key
38+
39+
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
40+
41+
#### Authenticate using an X.509 certificate
42+
43+
[!INCLUDE [iot-hub-howto-auth-device-cert-node](iot-hub-howto-auth-device-cert-node.md)]
44+
45+
#### Authenticate using a shared access key
46+
47+
##### Choose a transport protocol
3348

3449
The `Client` object supports these protocols:
3550

@@ -49,7 +64,7 @@ npm install azure-iot-device-amqp --save
4964

5065
For more information about the differences between MQTT, AMQP, and HTTPS support, see [Cloud-to-device communications guidance](../articles/iot-hub/iot-hub-devguide-c2d-guidance.md) and [Choose a communication protocol](../articles/iot-hub/iot-hub-devguide-protocols.md).
5166

52-
### Create a client object
67+
##### Create a client object
5368

5469
Create a `Client` object using the installed package.
5570

@@ -59,7 +74,7 @@ For example:
5974
const Client = require('azure-iot-device').Client;
6075
```
6176

62-
### Create a protocol object
77+
##### Create a protocol object
6378

6479
Create a `Protocol` object using an installed transport package.
6580

@@ -69,7 +84,7 @@ This example assigns the AMQP protocol:
6984
const Protocol = require('azure-iot-device-amqp').Amqp;
7085
```
7186

72-
### Add the device connection string and transport protocol
87+
##### Add the device connection string and transport protocol
7388

7489
Call [fromConnectionString](/javascript/api/azure-iot-device/client?#azure-iot-device-client-fromconnectionstring) to supply device connection parameters:
7590

@@ -84,7 +99,7 @@ const Protocol = require('azure-iot-device-mqtt').Amqp;
8499
let client = Client.fromConnectionString(deviceConnectionString, Protocol);
85100
```
86101

87-
### Open the connection to IoT Hub
102+
##### Open the connection to IoT Hub
88103

89104
Use the [open](/javascript/api/azure-iot-device/client?#azure-iot-device-client-open) method to open connection between an IoT device and IoT Hub.
90105

includes/iot-hub-howto-device-management-python.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: iot-hub
88
ms.devlang: csharp
99
ms.topic: include
10-
ms.date: 11/25/2024
10+
ms.date: 1/6/2025
1111
ms.custom: mqtt, devx-track-python, py-fresh-zinc
1212
---
1313

@@ -35,9 +35,9 @@ pip install azure-iot-hub
3535

3636
This section describes how to use device application code to create a direct method callback listener.
3737

38-
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
38+
The [IoTHubDeviceClient](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient) class contains methods that can be used to work with direct methods.
3939

40-
### Device import statements
40+
### Device import statement
4141

4242
Add this import statement to access `IoTHubDeviceClient` and `MethodResponse`.
4343

@@ -48,7 +48,14 @@ from azure.iot.device import IoTHubDeviceClient, MethodResponse
4848

4949
### Connect to a device
5050

51-
The [IoTHubDeviceClient](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient) class contains methods that can be used to work with direct methods.
51+
A device app can authenticate with IoT Hub using the following methods:
52+
53+
* Shared access key
54+
* X.509 certificate
55+
56+
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
57+
58+
#### Authenticate using a shared access key
5259

5360
Use [create_from_connection_string](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-create-from-connection-string) to connect an application to a device using a device connection string.
5461

@@ -59,6 +66,10 @@ conn_str = "{IoT hub device connection string}"
5966
device_client = IoTHubDeviceClient.create_from_connection_string(conn_str)
6067
```
6168

69+
#### Authenticate using an X.509 certificate
70+
71+
[!INCLUDE [iot-hub-howto-auth-device-cert-python](iot-hub-howto-auth-device-cert-python.md)]
72+
6273
### Create a direct method callback
6374

6475
Use [on_method_request_received](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-on-method-request-received) to create a handler function or coroutine that is called when a direct method is received. The listener is associated with a method name keyword, such as "reboot". The method name can be used in an IoT Hub or backend application to trigger the callback method on the device.
@@ -157,7 +168,7 @@ To invoke a direct method on a device:
157168
1. Create a [CloudToDeviceMethod](/python/api/azure-iot-hub/azure.iot.hub.protocol.models.cloudtodevicemethod) object. Supply the method name and payload as parameters.
158169
1. Call [invoke_device_method](/python/api/azure-iot-hub/azure.iot.hub.iothub_registry_manager.iothubregistrymanager?#azure-iot-hub-iothub-registry-manager-iothubregistrymanager-invoke-device-method) to invoke a direct method on a device. Supply the device ID and `CloudToDeviceMethod` payload object as parameters.
159170

160-
This example calls `CloudToDeviceMethod` to invoke a direct method named "rebootDevice" on a device. After the direct method has been successfully invoked, the direct method response payload is displayed.
171+
This example calls `CloudToDeviceMethod` to invoke a direct method named "rebootDevice" on a device. After the direct method is successfully invoked, the direct method response payload is displayed.
161172

162173
```python
163174
CONNECTION_STRING = "{IoTHubConnectionString}"

0 commit comments

Comments
 (0)