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
* Make sure that port 8883 is open in your firewall. The device sample in this article uses MQTT protocol, which 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-hub-mqtt-support.md#connecting-to-iot-hub).
29
29
@@ -48,34 +48,25 @@ In this section, you create a Python console app that adds location metadata to
48
48
1. In your working directory, open a command prompt and install the **Azure IoT Hub Service SDK for Python**.
49
49
50
50
```cmd/sh
51
-
pip install azure-iothub-service-client
51
+
pip install azure-iot-hub
52
52
```
53
53
54
-
> [!NOTE]
55
-
> The pip package for azure-iothub-service-client is currently available only for Windows OS. For Linux/Mac OS, please refer to the Linux and Mac OS-specific sections on the [Prepare your development environment for Python](https://github.com/Azure/azure-iot-sdk-python/blob/v1-deprecated/doc/python-devbox-setup.md) post.
56
-
>
57
-
58
54
2. Using a text editor, create a new **AddTagsAndQuery.py** file.
59
55
60
56
3. Add the following code to import the required modules from the service SDK:
4. Add the following code. Replace `[IoTHub Connection String]` with the IoT hub connection string you copied in [Get the IoT hub connection string](#get-the-iot-hub-connection-string). Replace `[Device Id]` with the device ID you registered in [Register a new device in the IoT hub](#register-a-new-device-in-the-iot-hub).
query_spec = QuerySpecification(query="SELECT * FROM devices WHERE tags.location.plant = 'Redmond43' AND properties.reported.connectivity = 'cellular'")
The **Registry**object exposes all the methods required to interact with device twins from the service. The code first initializes the **Registry**object, then updates the device twin for**deviceId**, andfinally runs two queries. The first selects only the device twins of devices located in the **Redmond43** plant, and the second refines the query to select only the devices that are also connected through cellular network.
110
+
The **IoTHubRegistryManager**object exposes all the methods required to interact with device twins from the service. The code first initializes the **IoTHubRegistryManager**object, then updates the device twin for**DEVICE_ID**, andfinally runs two queries. The first selects only the device twins of devices located in the **Redmond43** plant, and the second refines the query to select only the devices that are also connected through a cellular network.
128
111
129
112
6. Add the following code at the end of **AddTagsAndQuery.py** to implement the **iothub_service_sample_run** function:
130
113
131
114
```python
132
115
if__name__=='__main__':
133
-
print ( "Starting the IoT Hub Device Twins Python service sample..." )
116
+
print("Starting the IoT Hub Device Twins Python service sample...")
117
+
print()
134
118
135
119
iothub_service_sample_run()
136
120
```
@@ -224,7 +208,7 @@ In this section, you create a Python console app that connects to your hub as yo
224
208
python ReportConnectivity.py
225
209
```
226
210
227
-
You should see confirmation the device twins were updated.
211
+
You should see confirmation the device twin reported properties were updated. You'll see confirmation that the desired properties twin patch was received after you complete the next step.
0 commit comments