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+
1213from builtins import input
1314
1415# The service connection string to authenticate with your IoT hub.
2021# Details of the direct method to call.
2122METHOD_NAME = "SetTelemetryInterval"
2223METHOD_PAYLOAD = "10"
23- TIMEOUT = 60
2424
2525def 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