Skip to content

Commit b98c711

Browse files
committed
Edits
1 parent f27e230 commit b98c711

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ This article shows you how to develop two types of applications:
4747
* Language SDK requirements:
4848
* **.NET SDK** - Requires Visual Studio.
4949
* **Python SDK** - [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.
50+
51+
* Device applications require the **azure-iot-device** package. You can install the package using this command:
52+
53+
```cmd/sh
54+
pip install azure-iot-device
55+
```
56+
57+
* Service applications require the **azure-iot-hub** package. You can install the package using this command:
58+
59+
```cmd/sh
60+
pip install azure-iot-hub
61+
```
62+
5063
* **Java** - Requires [Java SE Development Kit 8](/azure/developer/java/fundamentals/). Make sure you select **Java 8** under **Long-term support** to navigate to downloads for JDK 8.
5164
* **Node.js** - Requires Node.js version 10.0.x or later.
5265

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ This section describes how to use device application code to:
2525

2626
[!INCLUDE [iot-authentication-device-connection-string.md](iot-authentication-device-connection-string.md)]
2727

28+
### Import statements
29+
30+
These import statements are required by `IoTHubDeviceClient`.
31+
32+
```python
33+
# import the device client library
34+
import asyncio
35+
from azure.iot.device.aio import IoTHubDeviceClient
36+
```
37+
2838
### Connect to a device
2939

3040
The [IoTHubDeviceClient](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient) class contains methods that can be used to work with direct methods.
@@ -34,10 +44,6 @@ To connect an application to a device:
3444
1. Call [connect](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-connect) to connect the device client to an Azure IoT hub
3545

3646
```python
37-
# import the device client library
38-
import asyncio
39-
from azure.iot.device.aio import IoTHubDeviceClient
40-
4147
# substitute the device connection string in conn_str
4248
# and add it to the IoTHubDeviceClient object
4349
conn_str = "{IOT hub device connection string}"
@@ -49,7 +55,7 @@ await device_client.connect()
4955

5056
### Create a direct method callback
5157

52-
Call [on_method_request_received](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?&#azure-iot-device-iothubdeviceclient-on-twin-desired-properties-patch-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.
58+
Call [on_method_request_received](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?view=azure-python&branch=main#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.
5359

5460
This example sets up a desired properties patch handler named `method_request_handler`.
5561

@@ -66,7 +72,7 @@ except:
6672

6773
In this example, the `method_request_handler` callback method implements the direct method on the device. This code updates reported properties related to a simulated device reboot. The reported properties can be read and verified by an IoT Hub or backend application, as demonstrated in the **Create a backend application** section of this article.
6874

69-
This example sets up a callback listener named `method_request_handler` that will trigger when the "rebootDevice" direct method name is called.
75+
This example sets up a callback listener named `method_request_handler` that triggers when the "rebootDevice" direct method is called from a service application.
7076

7177
```python
7278
# Define the handler for method requests
@@ -104,13 +110,13 @@ The Azure IoT SDK for Python provides a working sample of a device app that hand
104110

105111
## Create a backend application
106112

107-
This section describes how to initiate a remote reboot on a device using a direct method.
113+
This section describes how to initiate a remote reboot on a device using a direct method call from a backend service application.
108114

109115
The [IoTHubRegistryManager](/python/api/azure-iot-hub/azure.iot.hub.iothubregistrymanager) class exposes all methods required to create a backend application to send messages to a device.
110116

111117
### Import statements
112118

113-
Add these import statements to connect to Iot Hub, receive cloud-to-device methods, and call twin methods.
119+
Add these import statements to connect to Iot Hub, receive cloud-to-device methods, and call device twin methods.
114120

115121
```python
116122
import sys, time
@@ -125,7 +131,7 @@ Connect to IoT hub using [from_connection_string](/python/api/azure-iot-hub/azur
125131

126132
To invoke a direct method on a device through IoT Hub, your service needs the **service connect** permission. By default, every IoT Hub is created with a shared access policy named **service** that grants this permission.
127133

128-
As a parameter to `CreateFromConnectionString`, supply the **service** shared access policy. For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
134+
As a parameter to `CreateFromConnectionString`, supply the **service** shared access policy connection string. For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
129135

130136
For example:
131137

@@ -137,14 +143,14 @@ iothub_registry_manager = IoTHubRegistryManager.from_connection_string(IOTHUB_CO
137143

138144
### Invoke a method on a device
139145

140-
You can invoke a direct method on a device. The method name is mapped to a name, which is "rebootTime" in the examples within this article.
146+
You can invoke a direct method by name on a device. The method name identifies the method. The method name is "rebootTime" in the examples within this article.
141147

142148
To invoke a direct method on a device:
143149

144150
1. Create a [CloudToDeviceMethod](/python/api/azure-iot-hub/azure.iot.hub.protocol.models.cloudtodevicemethod) object. Supply the method name and payload as parameters.
145151
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.
146152

147-
This example invokes a direct method named "rebootDevice" on a device. The example then uses device twin queries to discover the last reboot time for the device that was updated in the **Create a direct method callback** section of this article.
153+
This example invokes a direct method named "rebootDevice" on a device. The example then uses device twin queries to discover the last reboot time for the device that was updated as described in the **Create a direct method callback** section of this article.
148154

149155
```python
150156
CONNECTION_STRING = "{IoTHubConnectionString}"

0 commit comments

Comments
 (0)