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
@@ -18,27 +18,27 @@ IoT Hub *direct methods* enable you to remotely invoke calls on devices from the
18
18
19
19
Each device method targets a single device. If you want to invoke direct methods on multiple devices, or schedule methods for disconnected devices, see [Schedule jobs on multiple devices](iot-hub-devguide-jobs.md).
20
20
21
-
Anyone with **service connect** permissions on IoT Hub may invoke a method on a device.
21
+
Anyone with **service connect** permissions on IoT Hub can invoke a method on a device.
22
22
23
-
Refer to the [Cloud-to-device communication guidance](iot-hub-devguide-c2d-guidance.md) if in doubt between using desired properties, direct methods, or cloud-to-device messages.
23
+
Refer to the [Cloud-to-device communications guidance](iot-hub-devguide-c2d-guidance.md) if in doubt between using desired properties, direct methods, or cloud-to-device messages.
24
24
25
25
## Method lifecycle
26
26
27
-
Direct methods are implemented on the device and may require zero or more inputs in the method payload to correctly instantiate. You invoke a direct method through a service-facing URI (`{iot hub}/twins/{device id}/methods/`). A device receives direct methods through a device-specific MQTT topic (`$iothub/methods/POST/{method name}/`) or through AMQP links (the `IoThub-methodname` and `IoThub-status` application properties).
27
+
Direct methods are implemented on the device and might require zero or more inputs in the method payload to correctly instantiate. You invoke a direct method through a service-facing URI (`{iot hub}/twins/{device id}/methods/`). A device receives direct methods through a device-specific MQTT topic (`$iothub/methods/POST/{method name}/`) or through AMQP links (the `IoThub-methodname` and `IoThub-status` application properties).
28
28
29
29
> [!NOTE]
30
30
> When you invoke a direct method on a device, property names and values can only contain US-ASCII printable alphanumeric, except any in the following set: `$ ( ) < > @ , ; : \ " / [ ] ? = { } SP HT`
31
31
>
32
32
33
-
Direct methods are synchronous and either succeed or fail after the timeout period (default 30 seconds; settable between 5 and 300 seconds). Direct methods are useful in interactive scenarios where you want a device to act if and only if the device is online and receiving commands. For example, turning on a light from a phone. In these scenarios, you want to see an immediate success or failure so the cloud service can act on the result as soon as possible. The device may return some message body as a result of the method, but it isn't required. There is no guarantee on ordering or any concurrency semantics on method calls.
33
+
Direct methods are synchronous and either succeed or fail after the time-out period (default 30 seconds; settable between 5 and 300 seconds). Direct methods are useful in interactive scenarios where you want a device to act if and only if the device is online and receiving commands. For example, turning on a light from a phone. In these scenarios, you want to see an immediate success or failure so the cloud service can act on the result as soon as possible. The device might return some message body as a result of the method, but it isn't required. There's no guarantee on ordering or any concurrency semantics on method calls.
34
34
35
35
Direct methods are HTTPS-only from the cloud side and MQTT, AMQP, MQTT over WebSockets, or AMQP over WebSockets from the device side.
36
36
37
37
The payload for method requests and responses is a JSON document up to 128 KB.
38
38
39
39
## Invoke a direct method from a back-end app
40
40
41
-
To invoke a direct method from a back-end app use the [Invoke device method](/rest/api/iothub/service/devices/invoke-method) REST API or its equivalent in one of the [IoT Hub service SDKs](iot-hub-devguide-sdks.md#azure-iot-hub-service-sdks).
41
+
To invoke a direct method from a back-end app, use the [Devices - Invoke Method](/rest/api/iothub/service/devices/invoke-method) REST API or its equivalent in one of the [IoT Hub service SDKs](iot-hub-devguide-sdks.md#azure-iot-hub-service-sdks).
42
42
43
43
### Method invocation
44
44
@@ -68,7 +68,7 @@ Direct method invocations on a device are HTTPS calls that are made up of the fo
68
68
}
69
69
```
70
70
71
-
The value provided as `responseTimeoutInSeconds` in the request is the amount of time that IoT Hub service must await for completion of a direct method execution on a device. Set this timeout to be at least as long as the expected execution time of a direct method by a device. If timeout is not provided, the default value of 30 seconds is used. The minimum and maximum values for `responseTimeoutInSeconds` are 5 and 300 seconds, respectively.
71
+
The value provided as `responseTimeoutInSeconds` in the request is the amount of time that IoT Hub service must await for completion of a direct method execution on a device. Set this time-out to be at least as long as the expected execution time of a direct method by a device. If a time-out value isn't provided, the default value of 30 seconds is used. The minimum and maximum values for `responseTimeoutInSeconds` are 5 and 300 seconds, respectively.
72
72
73
73
The value provided as `connectTimeoutInSeconds` in the request is the amount of time upon invocation of a direct method that IoT Hub service must await for a disconnected device to come online. The default value is 0, meaning that devices must already be online upon invocation of a direct method. The maximum value for `connectTimeoutInSeconds` is 300 seconds.
74
74
@@ -82,7 +82,7 @@ To begin, use the [Microsoft Azure IoT extension for Azure CLI](https://github.c
82
82
az iot hub generate-sas-token -n <iothubName> --du <duration>
83
83
```
84
84
85
-
Next, replace the Authorization header with your newly generated SharedAccessSignature, then modify the `iothubName`, `deviceId`, `methodName` and `payload` parameters to match your implementation in the example `curl` command below.
85
+
Next, replace the Authorization header with your newly generated SharedAccessSignature, then modify the `iothubName`, `deviceId`, `methodName`, and `payload` parameters to match your implementation in the following example `curl` command.
86
86
87
87
```bash
88
88
curl -X POST \
@@ -102,7 +102,7 @@ curl -X POST \
102
102
Execute the modified command to invoke the specified direct method. Successful requests return an HTTP 200 status code.
103
103
104
104
> [!NOTE]
105
-
> The example above demonstrates invoking a direct method on a device. If you want to invoke a direct method in an IoT Edge Module, modify the url request to include `/modules/<moduleName>` as shown below:
105
+
> The previous example demonstrates invoking a direct method on a device. If you want to invoke a direct method in an IoT Edge module, modify the URL request to include `/modules/<moduleName>` as shown in the following example:
@@ -114,8 +114,8 @@ The back-end app receives a response that is made up of the following items:
114
114
115
115
**HTTP status code*:
116
116
* 200 indicates successful execution of direct method;
117
-
* 404 indicates that either device ID is invalid, or that the device was not online upon invocation of a direct method and for`connectTimeoutInSeconds` thereafter (use accompanied error message to understand the root cause);
118
-
* 504 indicates gateway timeout caused by device not responding to a direct method call within `responseTimeoutInSeconds`.
117
+
* 404 indicates that either device ID is invalid, or that the device wasn't online upon invocation of a direct method and for `connectTimeoutInSeconds` thereafter (use accompanied error message to understand the root cause);
118
+
* 504 indicates gateway time-out caused by device not responding to a direct method call within `responseTimeoutInSeconds`.
119
119
120
120
* *Headers* that contain the request ID, content type, and content encoding.
121
121
@@ -132,7 +132,7 @@ The back-end app receives a response that is made up of the following items:
132
132
133
133
### Method invocation for IoT Edge modules
134
134
135
-
Invoking direct methods on a module is supported by the [Invoke module method](/rest/api/iothub/service/modules/invoke-method) REST API or its equivalent in one of the IoT Hub service SDKs.
135
+
To invoke a direct method on a module, use the [Modules - Invoke Method](/rest/api/iothub/service/modules/invoke-method) REST API or its equivalent in one of the [IoT Hub service SDKs](iot-hub-devguide-sdks.md#azure-iot-hub-service-sdks).
136
136
137
137
The `moduleId` is passed along with the `deviceId`in the request URI when using the REST API or as a parameter when using a service SDK. For example, `https://<iothubName>.azure-devices.net/twins/<deviceId>/modules/<moduleName>/methods?api-version=2021-04-12`. The request body and response is similar to that of direct methods invoked on the device.
138
138
@@ -142,11 +142,11 @@ On an IoT device, direct methods can be received over MQTT, AMQP, or either of t
142
142
143
143
### MQTT
144
144
145
-
The following section is for the MQTT protocol. To learn more about using the MQTT protocol directly with IoT Hub, see [MQTT protocol support](../iot/iot-mqtt-connect-to-iot-hub.md).
145
+
The following section is for the MQTT protocol. To learn more about using the MQTT protocol directly with IoT Hub, see [Communicate with an IoT hub using the MQTT protocol](../iot/iot-mqtt-connect-to-iot-hub.md).
146
146
147
147
#### Method invocation
148
148
149
-
Devices receive direct method requests on the MQTT topic: `$iothub/methods/POST/{method name}/?$rid={request id}`. However, the `request id` is generated by IoT Hub and cannot be known ahead of time, so subscribe to `$iothub/methods/POST/#` and then filter the delivered messages based on method names supported by your device. (You'll use the `request id` to respond.)
149
+
Devices receive direct method requests on the MQTT topic: `$iothub/methods/POST/{method name}/?$rid={request id}`. However, the `request id`can't be known ahead of time because IoT Hub generates it, so subscribe to `$iothub/methods/POST/#` and then filter the delivered messages based on method names supported by your device. (You use the generated `request id` to respond.)
150
150
151
151
The body that the device receives is in the following format:
152
152
@@ -167,11 +167,11 @@ The device sends responses to `$iothub/methods/res/{status}/?$rid={request id}`,
167
167
168
168
* The `$rid` property is the request ID from the method invocation received from IoT Hub. The request ID is a hexadecimal formatted value.
169
169
170
-
The body is set by the device and can be any status.
170
+
The device sets the body and can be any status.
171
171
172
172
### AMQP
173
173
174
-
The following section is for the AMQP protocol. To learn more about using the AMQP protocol directly with IoT Hub, see [AMQP protocol support](iot-hub-amqp-support.md).
174
+
The following section is for the AMQP protocol. To learn more about using the AMQP protocol directly with IoT Hub, see [Communicate with your IoT hub by using the AMQP Protocol](iot-hub-amqp-support.md).
175
175
176
176
#### Method invocation
177
177
@@ -199,9 +199,9 @@ The method's response is returned on the sending link and is structured as follo
199
199
200
200
## Next steps
201
201
202
-
Now you have learned how to use direct methods, you may be interested in the following IoT Hub developer guide article:
202
+
Now that you know how to use direct methods, you might be interested in the following IoT Hub developer guide articles:
203
203
204
204
* [Schedule jobs on multiple devices](iot-hub-devguide-jobs.md)
205
-
* [Azure IoT device and service SDKs](iot-hub-devguide-sdks.md) lists the various language SDKs you can use when you develop both device and service apps that interact with IoT Hub.
206
-
* [IoT Hub query language for device twins, jobs, and message routing](iot-hub-devguide-query-language.md) describes the IoT Hub query language you can use to retrieve information from IoT Hub about your device twins and jobs.
205
+
* [Azure IoT Hub SDKs](iot-hub-devguide-sdks.md) lists the various language SDKs you can use when you develop both device and service apps that interact with IoT Hub.
206
+
* [IoT Hub query language for device and module twins, jobs, and message routing](iot-hub-devguide-query-language.md) describes the IoT Hub query language you can use to retrieve information from IoT Hub about your device twins and jobs.
Copy file name to clipboardExpand all lines: includes/iot-hub-basic-whole.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
@@ -5,9 +5,9 @@
5
5
author: SoniaLopezBravo
6
6
ms.service: azure-iot-hub
7
7
ms.topic: include
8
-
ms.date: 04/01/2018
8
+
ms.date: 03/20/2025
9
9
ms.author: sonialopez
10
10
ms.custom: include file
11
11
---
12
12
>[!NOTE]
13
-
>The features described in this article are available only in the standard tier of IoT Hub. For more information about the basic and standard/free IoT Hub tiers, see [Choose the right IoT Hub tier for your solution](../articles/iot-hub/iot-hub-scaling.md).
13
+
>The features described in this article are available only in the standard tier of IoT Hub. For more information about the basic and standard/free IoT Hub tiers, see [Choose the right IoT Hub tier and size for your solution](../articles/iot-hub/iot-hub-scaling.md).
0 commit comments