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,89 +48,73 @@ 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).
print("Devices in Redmond43 plant: {}".format(', '.join([twin.device_id for twin in query_result.items])))
106
96
107
-
if twin_info.find(UPDATE_JSON_SEARCH) >-1:
108
-
print ( dev_list[device].deviceId )
97
+
print()
109
98
110
-
print ( "" )
99
+
query_spec = QuerySpecification(query="SELECT * FROM devices WHERE tags.location.plant = 'Redmond43' AND properties.reported.connectivity = 'cellular'")
print("IoT Hub Device Twin service sample stopped")
125
108
```
126
109
127
-
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 Python IoT Hub Device Twin service sample...")
117
+
print()
134
118
135
119
iothub_service_sample_run()
136
120
```
@@ -203,16 +187,16 @@ In this section, you create a Python console app that connects to your hub as yo
The **Client**object exposes all the methods you require to interact with device twins from the device. The previous code, after it initializes the **Client**object, retrieves the device twin for your device and updates its reported propertywith the connectivity information.
193
+
The **IoTHubModuleClient**object exposes all the methods you require to interact with device twins from the device. The previous code, after it initializes the **IoTHubModuleClient**object, retrieves the device twin for your device and updates its reported propertywith the connectivity information.
210
194
211
195
6. Add the following code at the end of **ReportConnectivity.py** to implement the **iothub_client_sample_run** function:
0 commit comments