Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 810dd54

Browse files
JimacoMS3jebrando
authored andcommitted
Updated BackEndApplication.py in iot-hub/Quickstarts for v2 SDK (#20)
* updated BackEndApplication.py in iot-hub/Quickstarts for v2 SDK * remvoed unused DevicedRegistryOperationStatus type from import statement
1 parent aabb34f commit 810dd54

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

iot-hub/Quickstarts/back-end-application/BackEndApplication.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import sys
2-
31
# Copyright (c) Microsoft. All rights reserved.
42
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
53

64
# Using the Python Device SDK for IoT Hub:
75
# https://github.com/Azure/azure-iot-sdk-python
8-
# The sample connects to a device-specific MQTT endpoint on your IoT Hub.
9-
import iothub_service_client
6+
# The sample connects to a device-specific HTTP endpoint on your IoT Hub.
7+
import sys
108
# pylint: disable=E0611
11-
from iothub_service_client import IoTHubDeviceMethod, IoTHubError
9+
10+
from azure.iot.hub import IoTHubRegistryManager
11+
from azure.iot.hub.protocol.models import CloudToDeviceMethod, CloudToDeviceMethodResult
12+
1213
from builtins import input
1314

1415
# The service connection string to authenticate with your IoT hub.
@@ -20,15 +21,15 @@
2021
# Details of the direct method to call.
2122
METHOD_NAME = "SetTelemetryInterval"
2223
METHOD_PAYLOAD = "10"
23-
TIMEOUT = 60
2424

2525
def iothub_devicemethod_sample_run():
2626
try:
27-
# Connect to your hub.
28-
iothub_device_method = IoTHubDeviceMethod(CONNECTION_STRING)
27+
# Create IoTHubRegistryManager
28+
registry_manager = IoTHubRegistryManager(CONNECTION_STRING)
2929

3030
# Call the direct method.
31-
response = iothub_device_method.invoke(DEVICE_ID, METHOD_NAME, METHOD_PAYLOAD, TIMEOUT)
31+
deviceMethod = CloudToDeviceMethod(method_name=METHOD_NAME, payload=METHOD_PAYLOAD)
32+
response = registry_manager.invoke_device_method(DEVICE_ID, deviceMethod)
3233

3334
print ( "" )
3435
print ( "Device Method called" )
@@ -40,9 +41,9 @@ def iothub_devicemethod_sample_run():
4041

4142
input("Press Enter to continue...\n")
4243

43-
except IoTHubError as iothub_error:
44+
except Exception as ex:
4445
print ( "" )
45-
print ( "Unexpected error {0}".format(iothub_error) )
46+
print ( "Unexpected error {0}".format(ex) )
4647
return
4748
except KeyboardInterrupt:
4849
print ( "" )

0 commit comments

Comments
 (0)