def result_from_register(registration_id, device_cert_file, device_key_file, protocol): x509 = X509(cert_file=device_cert_file, key_file=device_key_file, pass_phrase=device_password) protocol_boolean_mapping = {"mqtt": False, "mqttws": True} provisioning_device_client = ProvisioningDeviceClient.create_from_x509_certificate( provisioning_host=PROVISIONING_HOST, registration_id=registration_id, id_scope=ID_SCOPE, x509=x509, websockets=protocol_boolean_mapping[protocol], ) return provisioning_device_client.register()
def result_from_register(registration_id, device_cert_file, device_key_file): x509 = X509(cert_file=device_cert_file, key_file=device_key_file, pass_phrase=device_password) provisioning_device_client = ProvisioningDeviceClient.create_from_x509_certificate( provisioning_host=PROVISIONING_HOST, registration_id=registration_id, id_scope=ID_SCOPE, x509=x509, ) return provisioning_device_client.register()
import uuid provisioning_host = os.getenv("PROVISIONING_HOST") id_scope = os.getenv("PROVISIONING_IDSCOPE") registration_id = os.getenv("DPS_X509_REGISTRATION_ID") x509 = X509( cert_file=os.getenv("X509_CERT_FILE"), key_file=os.getenv("X509_KEY_FILE"), pass_phrase=os.getenv("PASS_PHRASE"), ) provisioning_device_client = ProvisioningDeviceClient.create_from_x509_certificate( provisioning_host=provisioning_host, registration_id=registration_id, id_scope=id_scope, x509=x509, ) registration_result = provisioning_device_client.register() # The result can be directly printed to view the important details. print(registration_result) if registration_result.status == "assigned": print("Will send telemetry from the provisioned device") # Create device client from the above result device_client = IoTHubDeviceClient.create_from_x509_certificate( x509=x509, hostname=registration_result.registration_state.assigned_hub, device_id=registration_result.registration_state.device_id,