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: articles/iot-hub/how-to-device-twins.md
+3-9Lines changed: 3 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,17 +38,11 @@ This article shows you how to develop two types of applications:
38
38
39
39
## Prerequisites
40
40
41
-
***An IoT hub**. Some SDK calls require the IoT Hub primary connection string, so make a note of the connection string.
41
+
* An IoT hub
42
42
43
-
***A registered device**. Some SDK calls require the device primary connection string, so make a note of the connection string.
43
+
* A registered device
44
44
45
-
* If your application uses the MQTT protocol, make sure that **port 8883** is open in your firewall. The MQTT protocol communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../iot/iot-mqtt-connect-to-iot-hub.md#connecting-to-iot-hub).
46
-
47
-
* Language SDK requirements:
48
-
***.NET SDK** - Requires Visual Studio.
49
-
***Python SDK** - [Python version 3.7 or later](https://www.python.org/downloads/) is recommended. Make sure to use the 32-bit or 64-bit installation as required by your setup. When prompted during the installation, make sure to add Python to your platform-specific environment variable.
50
-
***Java** - Requires [Java SE Development Kit 8](/azure/developer/java/fundamentals/). Make sure you select **Java 8** under **Long-term support** to navigate to downloads for JDK 8.
51
-
***Node.js** - Requires Node.js version 10.0.x or later.
45
+
* If your application uses the MQTT protocol, make sure that port 8883 is open in your firewall. The MQTT protocol communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../iot/iot-mqtt-connect-to-iot-hub.md#connecting-to-iot-hub).
This article describes how to use the [Azure IoT SDK for .NET](https://github.com/Azure/azure-iot-sdk-csharp/blob/main/readme.md) to create device and backend service application code for device twins.
@@ -25,13 +27,26 @@ This section describes how to use device application code to:
25
27
* Update reported device twin properties
26
28
* Create a desired property update callback handler
The [DeviceClient](/dotnet/api/microsoft.azure.devices.client.deviceclient) class exposes all the methods required to interact with device twins from the device.
Call [GetTwinAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.gettwinasync?#microsoft-azure-devices-client-deviceclient-gettwinasync) to retrieve the current device twin properties. There are many [Twin](/dotnet/api/microsoft.azure.devices.shared.twin?) object [properties](/dotnet/api/microsoft.azure.devices.shared.twin?&#properties) that you can use to access specific areas of the `Twin` JSON data including `Properties`, `Status`, `Tags`, and `Version`.
* Requires [Java SE Development Kit 8](/azure/developer/java/fundamentals/). Make sure you select **Java 8** under **Long-term support** to navigate to downloads for JDK 8.
15
+
14
16
## Overview
15
17
16
18
This article describes how to use the [Azure IoT SDK for Java](https://github.com/Azure/azure-iot-sdk-java) to create device and backend service application code for device twins.
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.
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-device-twins-node.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,8 @@ ms.date: 07/20/2024
11
11
ms.custom: mqtt, devx-track-js
12
12
---
13
13
14
+
* Requires Node.js version 10.0.x or later
15
+
14
16
## Overview
15
17
16
18
This article describes how to use the [Azure IoT SDK for Node.js](https://github.com/Azure/azure-iot-sdk-node) to create device and backend service application code for device twins.
@@ -27,14 +29,29 @@ This section describes how to use the [azure-iot-device](/javascript/api/azure-i
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.
39
56
40
57
### Choose a transport protocol
@@ -245,7 +262,7 @@ This section describes how to create a backend application that:
245
262
* Retrieves and updates a device twin
246
263
* Creates a device twin query
247
264
248
-
### Install service SDK packages
265
+
### Install service SDK package
249
266
250
267
Run this command to install **azure-iothub** on your development machine:
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-device-twins-python.md
+46-15Lines changed: 46 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,26 @@ ms.date: 07/12/2024
11
11
ms.custom: mqtt, devx-track-python, py-fresh-zinc
12
12
---
13
13
14
+
* Python SDK - [Python version 3.7 or later](https://www.python.org/downloads/) is recommended. Make sure to use the 32-bit or 64-bit installation as required by your setup. When prompted during the installation, make sure to add Python to your platform-specific environment variable.
15
+
14
16
## Overview
15
17
16
18
This article describes how to use the [Azure IoT SDK for Python](https://github.com/Azure/azure-iot-sdk-python) to create device and backend service application code for device twins.
17
19
20
+
## Install packages
21
+
22
+
The **azure-iot-device** library must be installed to create device applications.
23
+
24
+
```cmd/sh
25
+
pip install azure-iot-device
26
+
```
27
+
28
+
The **azure-iot-hub** library must be installed to create backend service applications.
29
+
30
+
```cmd/sh
31
+
pip install azure-iot-hub
32
+
```
33
+
18
34
## Create a device application
19
35
20
36
Device applications can read and write twin reported properties, and be notified of desired twin property changes that are set by a backend application or IoT Hub.
@@ -26,30 +42,45 @@ This section describes how to create device application code that:
26
42
* Retrieves a device twin and examine reported properties
27
43
* Patch reported device twin properties
28
44
45
+
### Device import statement
46
+
47
+
Add this code to import the `IoTHubDeviceClient` functions from the azure.iot.device SDK.
48
+
49
+
```python
50
+
from azure.iot.device import IoTHubDeviceClient
51
+
```
52
+
53
+
### Connect a device to IoT Hub
54
+
55
+
A device app can authenticate with IoT Hub using the following methods:
This section shows how to connect an application to a device using a device primary key that includes a shared access key.
64
+
To connect a device to IoT Hub:
34
65
35
-
To connect an application to a device:
36
-
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
37
-
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
66
+
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 primary connection string.
67
+
1. Call [connect](/python/api/azure-iot-device/azure.iot.device.iothubdeviceclient?#azure-iot-device-iothubdeviceclient-connect) to connect the device client.
38
68
39
-
```python
40
-
# import the device client library
41
-
import asyncio
42
-
from azure.iot.device.aio import IoTHubDeviceClient
69
+
For example:
43
70
44
-
# substitute the device connection string in conn_str
### Retrieve a device twin and examine reported properties
54
85
55
86
You can retrieve and examine device twin information including tags and properties. The device twin information retrieved matches device twin JSON-formatted data that you can view for a device in the Azure portal.
0 commit comments