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
In this section, you create a Node.js console app that responds to a method called by the cloud.
42
+
In this section, you create a Node.js console app that responds to a method called by the back end.
43
43
44
44
1. Create a new empty folder called **simulateddevice**. In the **simulateddevice** folder, create a package.json file using the following command at your command-prompt. Accept all the defaults:
45
45
46
46
```
47
47
npm init
48
48
```
49
-
2. At your command-prompt in the **simulateddevice** folder, run the following command to install the **azure-iot-device** Device SDK package and **azure-iot-device-mqtt** package:
49
+
2. At your command-prompt in the **simulateddevice** folder, run the following command to install the **azure-iot-device** and **azure-iot-device-mqtt** packages:
@@ -66,7 +66,7 @@ In this section, you create a Node.js console app that responds to a method call
66
66
var connectionString = '{device connection string}';
67
67
var client = DeviceClient.fromConnectionString(connectionString, Mqtt);
68
68
```
69
-
6. Add the following function to implement the method on the device:
69
+
6. Add the following function to implement the direct method on the device:
70
70
71
71
```
72
72
function onWriteLine(request, response) {
@@ -81,7 +81,7 @@ In this section, you create a Node.js console app that responds to a method call
81
81
});
82
82
}
83
83
```
84
-
7. Open the connection to your IoT hub and start initialize the method listener:
84
+
7. Open the connection to your IoT hub and initialize the method listener:
85
85
86
86
```
87
87
client.open(function(err) {
@@ -100,8 +100,8 @@ In this section, you create a Node.js console app that responds to a method call
100
100
>
101
101
>
102
102
103
-
## Call a method on a device
104
-
In this section, you create a Node.js console app that calls a method on the simulated device and then displays the response.
103
+
## Call a direct method on a device
104
+
In this section, you create a .NET console app that calls a method on the simulated device and then displays the response.
105
105
106
106
1. In Visual Studio, add a Visual C# Windows Classic Desktop project to the current solution by using the **Console Application** project template. Make sure the .NET Framework version is 4.5.1 or later. Name the project **CallMethodOnDevice**.
Copy file name to clipboardexpand all lines: articles/iot-hub/iot-hub-devguide-direct-methods.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -19,26 +19,26 @@ ms.author: nberdy
19
19
---
20
20
# Invoke a direct method on a device
21
21
## Overview
22
-
IoT Hub gives you ability to invoke methods on devices from the cloud. Methods represent a request-reply interaction with a device similar to an HTTP call in that they succeed or fail immediately (after a user-specified timeout). This is useful for scenarios where the course of immediate action is different depending on whether the device was able to respond, such as sending an SMS wake-up to a device if a device is offline (SMS being more expensive than a method call).
22
+
IoT Hub gives you ability to invoke direct methods on devices from the cloud. Direct methods represent a request-reply interaction with a device similar to an HTTP call in that they succeed or fail immediately (after a user-specified timeout). This is useful for scenarios where the course of immediate action is different depending on whether the device was able to respond, such as sending an SMS wake-up to a device if a device is offline (SMS being more expensive than a method call).
23
23
24
-
Each device method targets a single device. [Jobs][lnk-devguide-jobs] provide a way to invoke methods on multiple devices, and schedule method invocation for disconnected devices.
24
+
Each device method targets a single device. [Jobs][lnk-devguide-jobs] provide a way to invoke direct methods on multiple devices, and schedule method invocation for disconnected devices.
25
25
26
26
Anyone with **service connect** permissions on IoT Hub may invoke a method on a device.
27
27
28
28
### When to use
29
-
Methods follow a request-response pattern and are meant for communications that require immediate confirmation of their result, usually interactive control of the device, e.g. turn on a fan.
29
+
Direct methods follow a request-response pattern and are meant for communications that require immediate confirmation of their result, usually interactive control of the device, for example to turn on a fan.
30
30
31
31
Refer to [Cloud-to-device communication guidance][lnk-c2d-guidance] if in doubt between using desired properties, direct methods, or cloud-to-device messages.
32
32
33
33
## Method lifecycle
34
-
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}/`). We may support methods on additional device-side networking protocols in the future.
34
+
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}/`). We may support direct methods on additional device-side networking protocols in the future.
35
35
36
36
> [!NOTE]
37
37
> 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}``.
38
38
>
39
39
>
40
40
41
-
Methods are synchronous and either succeed or fail after the timeout period (default: 30 seconds, settable up to 3600 seconds). Methods are useful in interactive scenarios where you want a device to act if and only if the device is online and receiving commands, such as 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 for the method to do so. There is no guarantee on ordering or any concurrency semantics on method calls.
41
+
Direct methods are synchronous and either succeed or fail after the timeout period (default: 30 seconds, settable up to 3600 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, such as 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 for the method to do so. There is no guarantee on ordering or any concurrency semantics on method calls.
42
42
43
43
Device method calls are HTTP-only from the cloud side, and MQTT-only from the device side.
Copy file name to clipboardexpand all lines: articles/iot-hub/iot-hub-devguide-query-language.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -167,7 +167,7 @@ Note how the **query** object is instantiated with a page size (up to 1000), and
167
167
It is important to note that the query object exposes multiple **next\***, depending on the deserialization option required by the query, such as device twin or job objects, or plain Json to be used when using projections.
168
168
169
169
### Limitations
170
-
Currently, comparisons are supported only between primitive types (i.e. no objects), for instance `... WHERE properties.desired.config = properties.reported.config` is supported only if those properties have primitive values.
170
+
Currently, comparisons are supported only between primitive types (no objects), for instance `... WHERE properties.desired.config = properties.reported.config` is supported only if those properties have primitive values.
171
171
172
172
## Getting started with jobs queries
173
173
[Jobs][lnk-jobs] provide a way to execute operations on sets of devices. Each device twin contains the information of the jobs of which it is part in a collection called **jobs**.
@@ -200,7 +200,7 @@ Logically,
200
200
]
201
201
}
202
202
203
-
Currently, this collection is queriable as **devices.jobs** in the IoT Hub query language.
203
+
Currently, this collection is queryable as **devices.jobs** in the IoT Hub query language.
204
204
205
205
> [!IMPORTANT]
206
206
> Currently, the jobs property is never returned when querying device twins (i.e. queries that contains 'FROM devices'). It can only be accessed directly with queries using `FROM devices.jobs`.
0 commit comments