我看到了个人注册的代码,但找不到团体注册的代码。我需要将 1000 台设备批量注册到 Azure IOT 中心,并正在考虑分组注册。任何示例代码将不胜感激。
最佳答案
团体注册和批量个人注册应该都是可能的。来自 samples相关于How to manage device enrollments with Azure Device Provisioning Service SDKs :
批量个人注册
public async Task<List<IndividualEnrollment>> CreateBulkIndividualEnrollmentsAsync()
{
Console.WriteLine("\nCreating a new set of individualEnrollments...");
List<IndividualEnrollment> individualEnrollments = new List<IndividualEnrollment>();
foreach (var item in _registrationIds)
{
Attestation attestation = new TpmAttestation(item.Value);
individualEnrollments.Add(new IndividualEnrollment(item.Key, attestation));
}
Console.WriteLine("\nRunning the bulk operation to create the individualEnrollments...");
BulkEnrollmentOperationResult bulkEnrollmentOperationResult =
await _provisioningServiceClient.RunBulkEnrollmentOperationAsync(BulkOperationMode.Create, individualEnrollments).ConfigureAwait(false);
Console.WriteLine("\nResult of the Create bulk enrollment.");
Console.WriteLine(bulkEnrollmentOperationResult);
return individualEnrollments;
}
创建注册组
public async Task CreateEnrollmentGroupAsync()
{
Console.WriteLine("\nCreating a new enrollmentGroup...");
Attestation attestation = X509Attestation.CreateFromRootCertificates(_groupIssuerCertificate);
EnrollmentGroup enrollmentGroup =
new EnrollmentGroup(
EnrollmentGroupId,
attestation);
Console.WriteLine(enrollmentGroup);
Console.WriteLine("\nAdding new enrollmentGroup...");
EnrollmentGroup enrollmentGroupResult =
await _provisioningServiceClient.CreateOrUpdateEnrollmentGroupAsync(enrollmentGroup).ConfigureAwait(false);
Console.WriteLine("\nEnrollmentGroup created with success.");
Console.WriteLine(enrollmentGroupResult);
}
更新
看看device sample 。注册设备时无需指定注册类型(个人/团体)。与门户中定义的注册的关联是使用设备注册时使用的证书完成的。
更新2
参见Quickstart: Control a device connected to an IoT hub (.NET)查看如何与已注册到 IoT 中心的设备进行通信
希望对你有帮助!
关于azure - 如何将设备注册到 Azure IOT 中心的组注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53845505/