Skip to content

Commit 13896b8

Browse files
committed
Updates
1 parent 91ef12a commit 13896b8

File tree

4 files changed

+75
-63
lines changed

4 files changed

+75
-63
lines changed

includes/iot-hub-howto-device-twins-dotnet.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ using Microsoft.Azure.Devices.Client;
5252
using Microsoft.Azure.Devices.Shared;
5353
using Newtonsoft.Json;
5454

55-
static string DeviceConnectionString = "{IoT Hub device connection string}";
55+
static string DeviceConnectionString = "{IoT hub device connection string}";
5656
static _deviceClient = null;
5757
_deviceClient = DeviceClient.CreateFromConnectionString(DeviceConnectionString,
5858
TransportType.Mqtt);
@@ -162,7 +162,7 @@ To install the **Microsoft.Azure.Devices** NuGet package:
162162

163163
### Connect to IoT hub
164164

165-
Connect a backend application to a device using [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.deviceclient.createfromconnectionstring?#microsoft-azure-devices-client-deviceclient-createfromconnectionstring(system-string-microsoft-azure-devices-client-transporttype)). As a parameter, supply the **IoT Hub service connection string** that you created in the Prerequisites section. The backend application connects to the device through IoT Hub.
165+
Connect a backend application to a device using [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.deviceclient.createfromconnectionstring?#microsoft-azure-devices-client-deviceclient-createfromconnectionstring(system-string-microsoft-azure-devices-client-transporttype)). As a parameter, supply the **IoT Hub service connection string** that you created in the Prerequisites section.
166166

167167
```csharp
168168
using Microsoft.Azure.Devices;
@@ -177,7 +177,7 @@ You can retrieve current device twin fields into a [Twin](/dotnet/api/microsoft.
177177

178178
The `Twin` class includes [properties](/dotnet/api/microsoft.azure.devices.shared.twin?&#properties) that correspond to each section of a device twin. Use the `Twin` class properties to view and update device twin fields. You can use the `Twin` object properties to update multiple twin fields before writing the updates to the device using `UpdateTwinAsync`.
179179

180-
After making twin field updates, call [UpdateTwinAsync](/dotnet/api/microsoft.azure.devices.registrymanager.updatetwinasync?#microsoft-azure-devices-registrymanager-updatetwinasync(system-string-microsoft-azure-devices-shared-twin-system-string)) to write `Twin` object field updates back to a device. Use a `try` and `catch` logic coupled with an error handler to catch incorrectly formatted patch errors from `UpdateTwinAsync`.
180+
After making twin field updates, call [UpdateTwinAsync](/dotnet/api/microsoft.azure.devices.registrymanager.updatetwinasync?#microsoft-azure-devices-registrymanager-updatetwinasync(system-string-microsoft-azure-devices-shared-twin-system-string)) to write `Twin` object field updates back to a device. Use `try` and `catch` logic coupled with an error handler to catch incorrectly formatted patch errors from `UpdateTwinAsync`.
181181

182182
#### Read and update device twin tags
183183

@@ -205,7 +205,7 @@ var tagspatch =
205205
// Assign the patch to the Twin object
206206
twin.Tags["location"] = tagspatch;
207207

208-
// Apply the patch to update the device twin tags
208+
// Apply the patch to update the device twin tags section
209209
try
210210
{
211211
await registryManager.UpdateTwinAsync(twin.DeviceId, patch, twin.ETag);
@@ -218,7 +218,7 @@ catch (Exception e)
218218

219219
##### Update using a JSON string
220220

221-
You can also create and apply a device twin information update patch that contains a block of field updates, including different field types such as tags mixed with desired properties. IoT Hub parses and applies the patch if it is correctly formatted and the fields are updatable. For example, device twin reported properties cannot be updated by a backend application and the patch for these fields are not be applied.
221+
You can create and apply a JSON-formatted device twin information update patch. IoT Hub parses and applies the patch if it is correctly formatted.
222222

223223
This example calls `GetTwinAsync` to retrieve the current device twin fields into a `Twin` object, creates a JSON-formatted `tag` patch with region and plant location information, then calls `UpdateTwinAsync` to apply the patch to update the device twin. An error message is displayed if `UpdateTwinAsync` failed.
224224

@@ -249,9 +249,9 @@ catch (Exception e)
249249

250250
#### View and update twin desired properties
251251

252-
Use device twin [Properties.Desired](/dotnet/api/microsoft.azure.devices.shared.twinproperties.desired?#microsoft-azure-devices-shared-twinproperties-desired) to read and write device property information. Update twin `Desired` properties using a JSON-formatted patch.
252+
Use device twin [TwinProperties.Desired](/dotnet/api/microsoft.azure.devices.shared.twinproperties.desired?#microsoft-azure-devices-shared-twinproperties-desired) property to read and write device property information. Update twin `Desired` properties using a JSON-formatted patch.
253253

254-
This example calls `GetTwinAsync` to retrieve the current device twin fields into a `Twin` object, updates the twin `speed` desired property, and then calls `UpdateTwinAsync` to apply the patch to update the device twin.
254+
This example calls `GetTwinAsync` to retrieve the current device twin fields into a `Twin` object, updates the twin `speed` desired property, and then calls `UpdateTwinAsync` to apply the `Twin` object to update the device twin.
255255

256256
```csharp
257257
// Retrieve the device twin
@@ -265,14 +265,14 @@ await registryManager.UpdateTwinAsync(twin.DeviceId, twin, twin.ETag);
265265

266266
You can also apply twin updates using these SDK methods:
267267

268-
* Call [ReplaceTwinAsync](/dotnet/api/microsoft.azure.devices.registrymanager.replacetwinasync) to replace the entire device twin schema.
268+
* Call [ReplaceTwinAsync](/dotnet/api/microsoft.azure.devices.registrymanager.replacetwinasync) to replace the entire device twin.
269269
* Call [UpdateTwins2Async](/dotnet/api/microsoft.azure.devices.registrymanager.updatetwins2async) to update a list of twins previously created within the system.
270270

271271
### Create a device twin query
272272

273273
This section demonstrates two device twin queries. Device twin queries are SQL-like queries that return a result set of device twins.
274274

275-
To create a device twin query, call [CreateQuery](/dotnet/api/microsoft.azure.devices.registrymanager.createquery) to submit a digital twins SQL query and obtain an [IQuery](/dotnet/api/microsoft.azure.devices.iquery) Interface. You can optionally `CreateQuery` with a second parameter to specify a maximum number of items per page.
275+
To create a device twin query, call [CreateQuery](/dotnet/api/microsoft.azure.devices.registrymanager.createquery) to submit a twins SQL query and obtain an [IQuery](/dotnet/api/microsoft.azure.devices.iquery) Interface. You can optionally call `CreateQuery` with a second parameter to specify a maximum number of items per page.
276276

277277
Next call `GetNextAsTwinAsync` or `GetNextAsJsonAsync` method as many times as needed to retrieve all twin results.
278278

includes/iot-hub-howto-device-twins-java.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Device applications can read and write twin reported properties, and be notified
2323

2424
This section describes how to create device application code to:
2525

26-
* Retrieve a device twin and examine reported properties
26+
* Retrieve and view a device twin
2727
* Update reported device twin properties
2828
* Subscribe to desired property changes
2929

@@ -61,13 +61,14 @@ To connect to a device:
6161
client.open(true);
6262
```
6363

64-
### Retrieve a device twin and examine reported properties
64+
### Retrieve and view a device twin
6565

66-
After opening the client connection, call [getTwin](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicetwin?#com-microsoft-azure-sdk-iot-service-devicetwin-devicetwin-gettwin(com-microsoft-azure-sdk-iot-service-devicetwin-devicetwindevice)) to retrieve the current twin properties.
66+
After opening the client connection, call [getTwin](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicetwin?#com-microsoft-azure-sdk-iot-service-devicetwin-devicetwin-gettwin(com-microsoft-azure-sdk-iot-service-devicetwin-devicetwindevice)) to retrieve the current twin properties into a `Twin` object.
6767

6868
For example:
6969

7070
```java
71+
private static Twin twin;
7172
System.out.println("Getting current twin");
7273
twin = client.getTwin();
7374
System.out.println("Received current twin:");
@@ -82,9 +83,9 @@ To update reported properties:
8283

8384
1. Call [getReportedProperties](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicetwindevice?#com-microsoft-azure-sdk-iot-service-devicetwin-devicetwindevice-getreportedproperties()) to fetch the twin reported properties into a [TwinCollection](/java/api/com.microsoft.azure.sdk.iot.deps.twin.twincollection) object.
8485

85-
1. Use [put](/java/api/com.microsoft.azure.sdk.iot.deps.twin.twincollection?#com-microsoft-azure-sdk-iot-deps-twin-twincollection-put(java-lang-string-java-lang-object)) to update a reported property. Call `put` for each reported property update.
86+
1. Use [put](/java/api/com.microsoft.azure.sdk.iot.deps.twin.twincollection?#com-microsoft-azure-sdk-iot-deps-twin-twincollection-put(java-lang-string-java-lang-object)) to update a reported property within the `TwinCollection` object. Call `put` for each reported property update.
8687

87-
1. Use [updateReportedProperties](/java/api/com.microsoft.azure.sdk.iot.device.devicetwin.devicetwin?#com-microsoft-azure-sdk-iot-device-devicetwin-devicetwin-updatereportedproperties(java-util-set(com-microsoft-azure-sdk-iot-device-devicetwin-property))) to update the group of reported properties that were updated using the `put` method.
88+
1. Use [updateReportedProperties](/java/api/com.microsoft.azure.sdk.iot.device.devicetwin.devicetwin?#com-microsoft-azure-sdk-iot-device-devicetwin-devicetwin-updatereportedproperties(java-util-set(com-microsoft-azure-sdk-iot-device-devicetwin-property))) to apply the group of reported properties that were updated using the `put` method.
8889

8990
For example:
9091

@@ -159,6 +160,8 @@ To connect to IoT Hub to view and update device twin information:
159160
1. Use a [DeviceTwin](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicetwin?#com-microsoft-azure-sdk-iot-service-devicetwin-devicetwin-devicetwin(java-lang-string)) constructor to create the connection to IoT hub. The `DeviceTwin` object handles the communication with your IoT hub. As parameters, supply the **IoT Hub service connection string** that you created in the Prerequisites section and the `DeviceTwinClientOptions` object.
160161
1. The [DeviceTwinDevice](/java/api/com.microsoft.azure.sdk.iot.service.devicetwin.devicetwindevice) object represents the device twin with its properties and tags.
161162

163+
For example:
164+
162165
```java
163166
import com.microsoft.azure.sdk.iot.service.devicetwin.*;
164167
import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException;
@@ -218,7 +221,7 @@ To update device twin fields:
218221
twinClient.updateTwin(device);
219222
}
220223

221-
// Retrieve the device twin with the tag values from IoT Hub
224+
// Retrieve and display the device twin with the tag values from IoT Hub
222225
System.out.println("Device twin after update:");
223226
twinClient.getTwin(device);
224227
System.out.println(device);

includes/iot-hub-howto-device-twins-node.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,14 @@ This section describes how to use the [azure-iot-device](/javascript/api/azure-i
2929

3030
### Install SDK packages
3131

32-
Run these command to install the **azure-iot-device** device SDK, the **azure-iot-device-mqtt** on your development machine:
32+
Run this command to install the **azure-iot-device** device SDK on your development machine:
3333

3434
```cmd/sh
3535
npm init --yes
36-
npm install azure-iot-device azure-iot-device-mqtt --save
3736
```
3837

3938
The [azure-iot-device](/javascript/api/azure-iot-device) package contains objects that interface with IoT devices. The [Twin](/javascript/api/azure-iot-device/twin) class includes twin-specific objects. This section describes `Client` class code that is used to read and write device twin data.
4039

41-
### Create modules
42-
43-
Create Client and Protocol modules using the installed packages.
44-
45-
```javascript
46-
const Client = require('azure-iot-device').Client;
47-
const Protocol = require('azure-iot-device-mqtt').Mqtt;
48-
```
49-
5040
### Choose a transport protocol
5141

5242
The `Client` object supports these protocols:
@@ -57,31 +47,52 @@ The `Client` object supports these protocols:
5747
* `MqttWs`
5848
* `AmqpWs`
5949

50+
Install needed transport protocols on your development machine.
51+
52+
For example, this command installs the `Mqtt` protocol:
53+
54+
```cmd/sh
55+
npm install azure-iot-device azure-iot-device-mqtt --save
56+
```
57+
6058
For more information about the differences between MQTT, AMQP, and HTTPS support, see [Cloud-to-device communications guidance](../articles/iot-hub/iot-hub-devguide-c2d-guidance.md) and [Choose a communication protocol](../articles/iot-hub/iot-hub-devguide-protocols.md).
6159

62-
This example assigns the AMQP protocol to a `Protocol` variable.
60+
### Create Client and Protocol modules
61+
62+
Create a Client module using the installed package.
63+
64+
For example,
6365

6466
```javascript
65-
const Protocol = require('azure-iot-device-mqtt').Amqp;
67+
const Client = require('azure-iot-device').Client;
68+
```
69+
70+
Create a Protocol module using an installed transport package.
71+
72+
This example assigns the MQTT protocol:
73+
74+
```javascript
75+
const Protocol = require('azure-iot-device-mqtt').Mqtt;
6676
```
6777

6878
### Add the IoT Hub string and transport protocol
6979

70-
Call [fromConnectionString](/javascript/api/azure-iot-device/client?#azure-iot-device-client-fromconnectionstring) to establish a device-to-IoT hub connection using these parameters:
80+
Call [fromConnectionString](/javascript/api/azure-iot-device/client?#azure-iot-device-client-fromconnectionstring) to supply device connection parameters:
7181

7282
* **connStr** - A connection string which encapsulates "device connect" permissions for an IoT hub. The connection string contains Hostname, Device ID & Shared Access Key in this format:
73-
"HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>". See the prerequisites section for how to look up the device primary connection string.
83+
"HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>".
7484
* **transportCtor** - The transport protocol.
7585

7686
```javascript
87+
const deviceConnectionString = "{IoT hub device connection string}"
7788
const Protocol = require('azure-iot-device-mqtt').Amqp;
7889
let client = Client.fromConnectionString(deviceConnectionString, Protocol);
7990
```
8091

8192
### Open the connection to IoT Hub
8293

83-
Use the [open](/javascript/api/azure-iot-device/client?#azure-iot-device-client-open) method to open a connection between an IoT device and IoT Hub.
84-
Use `.catch(err)` to catch an error and call handler code.
94+
Use [open](/javascript/api/azure-iot-device/client?#azure-iot-device-client-open) method to open a connection between an IoT device and IoT Hub.
95+
Use `.catch(err)` to catch an error and execute handler code.
8596

8697
For example:
8798

@@ -94,19 +105,19 @@ client.open() //open the connection
94105

95106
### Retrieve a device twin and examine reported properties
96107

97-
Call [getTwin](/javascript/api/azure-iot-device/client?#azure-iot-device-client-gettwin-1) to assign the twin object. This object can be used to read device twin information.
108+
Call [getTwin](/javascript/api/azure-iot-device/client?#azure-iot-device-client-gettwin-1) to retrieve current device twin information into a [Twin](/javascript/api/azure-iot-device/twin) object.
98109

99110
For example:
100111

101112
```javascript
102-
client.getTwin(function(err, twin) {
113+
client.getTwin(function(err, twin))
103114
if (err)
104115
console.error('could not get twin');
105116
```
106117

107118
### Update reported device twin properties
108119

109-
Use [update](/javascript/api/azure-iothub/twin?#azure-iothub-twin-update) to update device reported properties. Include a JSON-formatted patch as the first parameter and callback method as the second parameter to the method.
120+
Use [update](/javascript/api/azure-iothub/twin?#azure-iothub-twin-update) to update device reported properties. Include a JSON-formatted patch as the first parameter and function execution status callback method as the second parameter to the method.
110121

111122
In this example, a JSON-formatted device twin patch is stored in the `patch` variable. The patch contains a device twin `connectivity` update value of `cellular`. The patch and error handler are passed to the `update` method. If there is an error, a console error message is displayed.
112123

@@ -134,9 +145,9 @@ The desired property event listener can take one of the following forms:
134145
135146
#### Receive all patches with a single event handler
136147
137-
You can create code to receive any desired property change.
148+
You can create a listener to receive any desired property change.
138149
139-
This code will output any properties that are received from the service.
150+
This example code outputs any properties that are received from the service.
140151
141152
```javascript
142153
twin.on('properties.desired', function (delta) {
@@ -147,7 +158,7 @@ twin.on('properties.desired', function (delta) {
147158
148159
#### Receive an event if anything changes under a properties grouping
149160
150-
You can create code to receive an event if anything under a property grouping changes.
161+
You can create a listener to receive an event if anything under a property grouping changes.
151162
152163
For example:
153164
@@ -181,7 +192,7 @@ For example:
181192
182193
You can set up a listener for a single property change. In this example, the code for this event is executed only if the `fanOn` boolean value is part of the patch. The code outputs the new desired `fanOn` state whenever the service updates it.
183194
184-
In this example, a backend application applies this desired property patch:
195+
1. A backend application applies this desired property patch:
185196
186197
```javascript
187198
const twinPatch2 = {
@@ -197,7 +208,7 @@ In this example, a backend application applies this desired property patch:
197208
};
198209
```
199210
200-
The listener triggers only when the `fanOn` property changes:
211+
1. The listener triggers only when the `fanOn` property changes:
201212
202213
```javascript
203214
twin.on('properties.desired.climate.hvac.systemControl', function (fanOn) {
@@ -215,15 +226,12 @@ The SDK contains two device twin samples:
215226
216227
## Create a backend application
217228
218-
A backend application:
219-
220-
* Connects to a device through IoT Hub
221-
* Can read device reported and desired properties, write device desired properties, and run device queries
229+
A backend application connects to a device through IoT Hub and can read device reported and desired properties, write device desired properties, and run device queries.
222230
223231
This section describes how to create a backend application that:
224232
225-
* Retrieve and update a device twin
226-
* Create a device twin query
233+
* Retrieves and updates a device twin
234+
* Creates a device twin query
227235
228236
### Install service SDK packages
229237
@@ -297,7 +305,7 @@ Use [createQuery](/javascript/api/azure-iothub/registry?#azure-iothub-registry-c
297305
* **sqlQuery** - The query written as an SQL string.
298306
* **pageSize** - The desired number of results per page (optional. default: 1000, max: 10000).
299307
300-
When the code creates the query object, it specifies the maximum number of returned documents in the second parameter. The query object contains a `hasMoreResults` boolean property that you can use to invoke the `nextAsTwin` methods multiple times to retrieve all results. A method called `next` is available for results that are not device twins, for example, the results of aggregation queries.
308+
If the **pageSize** parameter is specified, the query object contains a `hasMoreResults` boolean property that you can check and use the `nextAsTwin` method to get the next twin results page as many times as needed to retrieve all results. A method called `next` is available for results that are not device twins, for example, the results of aggregation queries.
301309
302310
This example query selects only the device twins of devices located in the `Redmond43` plant.
303311

0 commit comments

Comments
 (0)