如何在Azure IOT集线器中将设备注册到组注册? [英] How can I enroll a device to a group enrollment in Azure IOT hub?

查看:142
本文介绍了如何在Azure IOT集线器中将设备注册到组注册?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过个人注册的代码,但找不到团体注册的任何代码.我需要将一千台设备批量注册到Azure IOT Hub,并正在考虑组注册.任何示例代码都将不胜感激.

I have seen code for individual enrollment but I can't find any for group enrollment. I need to bulk enroll a thousand devices to Azure IOT Hub and was thinking of group enrollment.Any sample code will be appreciated.

推荐答案

组注册和批量个人注册都应该可行.来自样本如何使用Azure设备配置管理设备注册服务SDK :

It should be possible both with group enrollment and bulk individual enrollments. From the samples related to 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);
}

更新

看看设备示例.注册设备时无需指定注册类型(个人/组).与门户中定义的注册的相关性是使用设备注册时使用的证书来完成的.

Take a look at the device samples. You don't need to specify the enrollment type (individual/group) when registering the device. the correlation to the defined enrollment in the portal is done using the certificate the device uses when it registers.

更新2

请参见快速入门:控制连接的设备连接到IoT中心(.NET),以了解如何与已注册到 IoT中心

See Quickstart: Control a device connected to an IoT hub (.NET) to see how to communicate with a device that was already enrolled to IoT Hub

希望有帮助!

这篇关于如何在Azure IOT集线器中将设备注册到组注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆