Skip to content

Commit cc5bae3

Browse files
committed
Updates
1 parent b98c711 commit cc5bae3

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ zone_pivot_groups: iot-hub-howto-c2d-1
1414

1515
# Get started with device management
1616

17-
Back-end apps can use Azure IoT Hub primitives, such as [device twins](iot-hub-devguide-device-twins.md) and [direct methods](iot-hub-devguide-direct-methods.md), to remotely start and monitor device management actions on devices. This article shows you how a back-end app and a device app can work together to initiate and monitor a remote device reboot using IoT Hub.
17+
Back-end apps can use Azure IoT Hub primitives, such as [device twins](iot-hub-devguide-device-twins.md) and [direct methods](iot-hub-devguide-direct-methods.md), to remotely start and monitor device management actions on devices.
1818

19-
Use a direct method to initiate device management actions (such as reboot, factory reset, and firmware update) from a back-end app in the cloud. The device is responsible for:
19+
Use a direct method to initiate device management actions (such as reboot, factory reset, and firmware update) from a back-end app in the cloud.
20+
21+
The device is responsible for:
2022

2123
* Handling the method request sent from IoT Hub.
2224

2325
* Initiating the corresponding device-specific action on the device.
2426

2527
* Providing status updates through *reported properties* to IoT Hub.
2628

27-
You can use a back-end app in the cloud to run device twin queries to report on the progress of your device management actions.
29+
The back-end app can run device twin queries to report on the progress of the device management actions.
2830

29-
This article shows you how to develop two types of applications:
31+
This article shows you how a back-end app and a device app can work together to initiate and monitor a remote device reboot using IoT Hub:
3032

31-
* Device apps can call a direct method to reboot a device and report the last reboot time. Direct methods are invoked from the cloud.
32-
* Service apps can call a direct method in a device app through an IoT hub. The service app can display the response and updated reported properties.
33+
* A service app calls a direct method to reboot in a device app through an IoT hub. The service app then displays the response and updated reported properties.
34+
* A device app handles a direct method to reboot a device and updates the last reboot time.
3335

3436
[!INCLUDE [iot-hub-basic](../../includes/iot-hub-basic-whole.md)]
3537

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,33 @@ 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
28+
### Device import statements
2929

30-
These import statements are required by `IoTHubDeviceClient`.
30+
Add import statements for `IoTHubDeviceClient`.
3131

3232
```python
3333
# import the device client library
34-
import asyncio
35-
from azure.iot.device.aio import IoTHubDeviceClient
34+
import time
35+
import datetime
36+
from azure.iot.device import IoTHubDeviceClient, MethodResponse
3637
```
3738

3839
### Connect to a device
3940

4041
The [IoTHubDeviceClient](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient) class contains methods that can be used to work with direct methods.
4142

42-
To connect an application to a device:
43-
1. Call [create_from_connection_string](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-create-from-connection-string) to add the device connection string
44-
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
43+
Call [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.
4544

4645
```python
4746
# substitute the device connection string in conn_str
4847
# and add it to the IoTHubDeviceClient object
4948
conn_str = "{IOT hub device connection string}"
5049
device_client = IoTHubDeviceClient.create_from_connection_string(conn_str)
51-
52-
# connect the application to the device
53-
await device_client.connect()
5450
```
5551

5652
### Create a direct method callback
5753

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.
54+
Call [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.
5955

6056
This example sets up a desired properties patch handler named `method_request_handler`.
6157

@@ -114,7 +110,7 @@ This section describes how to initiate a remote reboot on a device using a direc
114110

115111
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.
116112

117-
### Import statements
113+
### Service import statements
118114

119115
Add these import statements to connect to Iot Hub, receive cloud-to-device methods, and call device twin methods.
120116

0 commit comments

Comments
 (0)