You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-device-management-dotnet.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,8 +158,6 @@ To invoke a direct method on a device through IoT Hub, your service needs the **
158
158
159
159
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).
stringconnectionString="{IoT hub service shared access policy connection string}";
@@ -177,10 +175,10 @@ To invoke a method on a device:
177
175
1. Create a [CloudToDeviceMethod](/dotnet/api/microsoft.azure.devices.cloudtodevicemethod) object. Pass the device direct method name as a parameter.
178
176
1. Call [InvokeDeviceMethodAsync](/dotnet/api/microsoft.azure.devices.serviceclient.invokedevicemethodasync?#microsoft-azure-devices-serviceclient-invokedevicemethodasync(system-string-microsoft-azure-devices-cloudtodevicemethod-system-threading-cancellationtoken)) to invoke the method on the device.
179
177
180
-
This example calls the "reboot" method to initiate a reboot on the device. The "reboot" method is mapped to a listener on the device as described in the [Create a direct method callback](#create-a-direct-method-callback) section of this article.
178
+
This example calls the "reboot" method to initiate a reboot on the device. The "reboot" method is mapped to a listener on the device as described in the [Create a direct method callback listener](#create-a-direct-method-callback-listener) section of this article.
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.
62
68
69
+
The listener should call [DirectMethodResponse](/java/api/com.microsoft.azure.sdk.iot.device.twin.directmethodresponse) to send a method response acknowledgment to the calling application.
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-device-management-node.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ ms.date: 11/25/2024
11
11
ms.custom: mqtt, devx-track-js
12
12
---
13
13
14
-
* Requires Node.js version 10.0.x or later.
14
+
* Requires Node.js version 10.0.x or later
15
15
16
16
## Overview
17
17
@@ -111,7 +111,7 @@ This example sets up a direct method handler named `onReboot` that is called whe
111
111
client.onDeviceMethod('reboot', onReboot);
112
112
```
113
113
114
-
In this example, the `onReboot` callback method implements the direct method on the device. The code is executed when the "reboot" direct method is called from a service application.
114
+
In this example, the `onReboot` callback method implements the direct method on the device. The code is executed when the "reboot" direct method is called from a service application. The function calls `send` to send a response acknowledgment message to the calling application.
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.
65
65
66
-
The handler function should call [MethodResponse](/python/api/azure-iot-device/azure.iot.device.methodresponse) to send a response acknowledgment to the calling application.
66
+
The handler function should create a [MethodResponse](/python/api/azure-iot-device/azure.iot.device.methodresponse)and pass it to [send_method_response](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-send-method-response) to send a direct method response acknowledgment to the calling application.
67
67
68
68
This example sets up a direct method handler named `method_request_handler`.
69
69
@@ -76,7 +76,7 @@ except:
76
76
client.shutdown()
77
77
```
78
78
79
-
In this example, the `method_request_handler` callback method implements the direct method on the device. The code is executed when the "rebootDevice" direct method is called from a service application. The method calls `MethodResponse` to send a response acknowledgment to the calling application.
79
+
In this example, the `method_request_handler` callback method implements the direct method on the device. The code is executed when the "rebootDevice" direct method is called from a service application. The method calls `send_method_response` to send a direct method response acknowledgment to the calling application.
80
80
81
81
```python
82
82
# Define the handler for method requests
@@ -189,4 +189,7 @@ except Exception as ex:
189
189
190
190
### SDK service samples
191
191
192
-
The Azure IoT SDK for Python provides a working sample of a service app that handles direct method tasks. For more information, see [Service helper sync](https://github.com/Azure/azure-iot-sdk-python/blob/e75d1c2026eab939d5d31097fd0c22924c53abf8/dev_utils/dev_utils/service_helper_sync.py).
192
+
The Azure IoT SDK for Python provides working samples of service apps that handle direct method tasks. For more information, see:
0 commit comments