azure - 如何将设备注册到 Azure IOT 中心的组注册?

标签 azure iot azure-iot-hub

我看到了个人注册的代码,但找不到团体注册的代码。我需要将 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/

相关文章:

迁移到 Azure 应用服务和 Azure Database for MySQL 灵活服务器后,Wordpress 网站速度极慢

azure - 如何使用托管磁盘的托管 HSM 中存储的客户管理 key 启用服务器端加密?

module - 将 IOT 模块连接到互联网服务器

sockets - Linux 用户空间代码,用于在 Linux 板和运行 contiki udp 发送器示例代码的每个节点之间进行通信

rest - AWS 物联网休息 API

azure-iot-hub - 如果那里已经有不同的记录,则用于报告孪生属性的 Azure IoT 设备更新会失败

xml - 如何在 XML 中转义这个(盐)字符串?

azure - 操作需要时间时重试消息

c# - 在 Azure Function 中处理从查询到 Azure IOT Hub 的 JSON 响应

c# - 获取IoT边缘设备现有子设备列表