How to create device in azure-iot-hub=2.6.0

jiah xie 21 Reputation points
2022-06-22T08:24:21.43+00:00

I once used sdk for python azure-iothub-service-client==1.4.6 to create device. Some code I used was like this as suggested:
new_device = IoTHubRegistryManager(self.connect_string).create_device(str(device_id), "", "", IoTHubRegistryManagerAuthMethod.SHARED_PRIVATE_KEY) .
But recently, I need to update the azure-iothub-service-client and found it had renamed and the method create_device in class IoTHubRegistryManager has been removed. Some similar methods suggested are
create_device_with_sas 、create_device_with_x509 and create_device_with_certificate_authority .
I can't figure out to choose which one to leave the logic unchanged.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,241 questions
0 comments No comments
{count} votes

Accepted answer
  1. chbeier 1,871 Reputation points
    2022-06-22T12:17:19.403+00:00

    Hello @jiah xie ,

    As I understand, you used a shared private key before. Thus, if you use create_device_with_sas you should be fine. The only thing to change is skipping auth_method and providing the targeted device state (enabled/disabled).

    azure-iot-sdk-python v1.4.6:

    new_device = iothub_registry_manager.create_device(DEVICE_ID, primary_key, secondary_key, auth_method)  
       
    

    With the current sdk version

    new_device = iothub_registry_manager.create_device_with_sas(device_id, primary_key, secondary_key, device_state)  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.