How do I map IoTHub in Device Provisioning Service enrollment list? - Enrollment status “unassigned”

五迷三道 提交于 2019-12-13 02:16:43

问题


I have a Azure device provisioning service setup entitled "myDPS" and below IoT hubs are linked.

  1. IoTHub-Dev-Asia
  2. IoTHub-Prod-Europe

Currently there are no enrollment list. The below c# code I am using to enroll the device

private const string RegistrationId = "TestRegID";
private const string OptionalDeviceId = "Device1";
private const ProvisioningStatus OptionalProvisioningStatus = ProvisioningStatus.Enabled;
private const string SampleTpmEndorsementKey = "***"// Key generated using TPM Simulator

static async Task SetRegistrationDataAsync()
{
   Console.WriteLine("Starting SetRegistrationData");
   Attestation attestation = new TpmAttestation(SampleTpmEndorsementKey);
   IndividualEnrollment individualEnrollment = new 
   IndividualEnrollment(RegistrationId, attestation);
   individualEnrollment.DeviceId = OptionalDeviceId;
   individualEnrollment.ProvisioningStatus = OptionalProvisioningStatus;
   Console.WriteLine("\nAdding new individualEnrollment...");
   var serviceClient = ProvisioningServiceClient.CreateFromConnectionString(ServiceConnectionString);
   IndividualEnrollment individualEnrollmentResult =
    await  serviceClient.CreateOrUpdateIndividualEnrollmentAsync(individualEnrollment).ConfigureAwait(false);
    Console.WriteLine("\nIndividualEnrollment created with success.");
    Console.WriteLine(individualEnrollmentResult);
}

The above code successfully enrolls the device to the DPS but status shows as unassigned

Issue#1 - Enrollment status unassigned, sometimes shows FAILED Status: failed Error code: 404201

Issue#2 Once above issue resolved, then I would like to have some configuration where I can specify which device should map to which IoT, so that device can automatically decide it's target IoT hubs.

Example:

Device1->IoTHub-Dev-Asia

Device2->IoTHub-Dev-Asia

Device3->IoTHub-Dev-Europe

I assume Static configuration via the enrollment list can help but not sure how to use it?


回答1:


The three supported allocation policies determine how devices are assigned to an IoT hub:

  1. Lowest latency: Devices are provisioned to an IoT hub based on the hub with the lowest latency to the device.
  2. Evenly weighted distribution (default): Linked IoT hubs are equally likely to have devices provisioned to them. This is the default setting. If you are provisioning devices to only one IoT hub, you can keep this setting.
  3. Static configuration via the enrollment list: Specification of the desired IoT hub in the enrollment list takes priority over the DPS-level allocation policy.

If you need to assign the device ,you should use a single call to the ProvisioningDeviceClient.RegisterAsync() API. You can refer to the sample.In the sample, you need to replace the RegistrationId with that your created before.



来源:https://stackoverflow.com/questions/50265386/how-do-i-map-iothub-in-device-provisioning-service-enrollment-list-enrollment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!