如何重新预配设备How to reprovision devices

在 IoT 解决方案的生命周期中,设备在 IoT 中心之间频繁移动。During the lifecycle of an IoT solution, it is common to move devices between IoT hubs. 此项移动的原因可能包括以下情况:The reasons for this move may include the following scenarios:

  • 地理位置:当设备在两个位置之间移动时,通过将设备迁移到离每个位置更近的 IoT 中心来改善网络延迟。Geolocation: As a device moves between locations, network latency is improved by having the device migrated to an IoT hub closer to each location.

  • 多租户:可在同一 IoT 解决方案中使用设备,但将其重新分配或租赁给新的客户或客户站点。Multi-tenancy: A device could be used within the same IoT solution but, reassigned or leased to a new customer, or customer site. 可使用不同的 IoT 中心为这位新客户提供服务。This new customer may be serviced using a different IoT hub.

  • 解决方案更改:可将设备移到新版或更新后的 IoT 解决方案中。Solution change: A device could be moved into a new or updated IoT solution. 这种重新分配可能需要设备与连接到其他后端组件的新 IoT 中心通信。This reassignment may require that the device communicate with a new IoT hub that is connected to other backend components.

  • 隔离:类似于解决方案更改。Quarantine: Similar to a solution change. 出现故障、被盗用或已过时的设备可能会重新分配到 IoT 中心,该设备只能在此处进行更新并恢复其符合性。A device that is malfunctioning, compromised, or out-of-date may be reassigned to an IoT hub where all it can do is update and get back in compliance. 一旦设备正常运行,它就会迁移回主中心。Once the device is functioning properly, it is then migrated back to its main hub.

有关更详细的重新预配概述,请参阅 IoT 中心设备重新预配概念For more a more detailed overview of reprovisioning, see IoT Hub Device reprovisioning concepts.

配置注册分配策略Configure the enrollment allocation policy

分配策略决定了在重新预配与注册关联的设备之后如何将其分配到 IoT 中心。The allocation policy determines how the devices associated with the enrollment will be allocated, or assigned, to an IoT hub once reprovisioned.

下面的步骤可配置设备注册项的分配策略:The following steps configure the allocation policy for a device's enrollment:

  1. 登录到 Azure 门户,并导航到设备预配服务实例。Sign in to the Azure portal and navigate to your Device Provisioning Service instance.

  2. 单击“管理注册”,再单击要配置进行重新预配的注册组或单个注册项 。Click Manage enrollments, and click the enrollment group or individual enrollment that you want to configure for reprovisioning.

  3. 在“选择要如何将设备分配到中心”下,选择下述一个分配策略 :Under Select how you want to assign devices to hubs, select one of the following allocation policies:

    • 最低延迟:此策略将设备分配到所链接的 IoT 中心,这可使设备与 IoT 中心之间的通信延迟降至最低。Lowest latency: This policy assigns devices to the linked IoT Hub that will result in the lowest latency communications between device and IoT Hub. 此选项允许设备根据位置与最近的 IoT 中心进行通信。This option enables the device to communicate with the closest IoT hub based on location.

    • 均匀加权分发:此策略根据分配到所链接的每个 IoT 中心的分配加权跨链接的 IoT 中心分发设备。Evenly weighted distribution: This policy distributes devices across the linked IoT Hubs based on the allocation weight assigned to each linked IoT hub. 通过此策略,你可根据所链接的一组中心上设置的分配加权跨这些中心实现设备的负载均衡。This policy allows you to load balance devices across a group of linked hubs based on the allocation weights set on those hubs. 如果只将设备预配到一个 IoT 中心,推荐使用此设置。If you are provisioning devices to only one IoT Hub, we recommend this setting. 此设置为默认设置。This setting is the default.

    • 静态配置:此策略规定对于要预配的设备,必须在注册项中列出所需的 IoT 中心。Static configuration: This policy requires a desired IoT Hub be listed in the enrollment entry for a device to be provisioned. 通过此策略,你可指定要向其分配设备的单个特定 IoT 中心。This policy allows you to designate a single specific IoT hub that you want to assign devices to.

  4. 在“选择可将此组分配到的 IoT 中心”下,选择要随附分配策略包含在内的已链接的 IoT 中心 。Under Select the IoT hubs this group can be assigned to, select the linked IoT hubs that you want included with your allocation policy. (可选)使用“链接新的 IoT 中心”按钮添加新链接的 IoT 中心 。Optionally, add a new linked Iot hub using the Link a new IoT Hub button.

    通过“最低延迟”分配策略,延迟评估时将纳入你所选的中心,从而确定用于设备分配的最近中心 。With the Lowest latency allocation policy, the hubs you select will be included in the latency evaluation to determine the closest hub for device assignment.

    通过“均匀加权分发”分配策略,设备将根据其配置的分配加权和当前设备负载在不同的中心之间实现负载均衡 。With the Evenly weighted distribution allocation policy, devices will be load balanced across the hubs you select based on their configured allocation weights and their current device load.

    而通过“静态配置”分配策略,可选择要向其分配设备的 IoT 中心 。With the Static configuration allocation policy, select the IoT hub you want devices assigned to.

  5. 单击“保存”或继续到下一部分来设备重新预配策略 。Click Save, or proceed to the next section to set the reprovisioning policy.

    选择注册分配策略

设置重新预配策略Set the reprovisioning policy

  1. 登录到 Azure 门户,并导航到设备预配服务实例。Sign in to the Azure portal and navigate to your Device Provisioning Service instance.

  2. 单击“管理注册”,再单击要配置进行重新预配的注册组或单个注册项 。Click Manage enrollments, and click the enrollment group or individual enrollment that you want to configure for reprovisioning.

  3. 在“选择在重新预配到其他 IoT 中心时要如何处理设备数据”下,选择下述一个重新配置策略 :Under Select how you want device data to be handled on re-provision to a different IoT hub, choose one of the following reprovisioning policies:

    • 重新预配并迁移数据:当与注册项关联的设备提交新的预配请求时,此策略将执行操作。Re-provision and migrate data: This policy takes action when devices associated with the enrollment entry submit a new provisioning request. 根据注册项配置,可将设备重新分配给其他 IoT 中心。Depending on the enrollment entry configuration, the device may be reassigned to another IoT hub. 如果设备正在更改 IoT 中心,则将删除初始 IoT 中心内的设备注册。If the device is changing IoT hubs, the device registration with the initial IoT hub will be removed. 来自该初始 IoT 中心的所有设备状态信息都将迁移到新的 IoT 中心。All device state information from that initial IoT hub will be migrated over to the new IoT hub. 迁移期间,设备的状态将报告为“正在分配” During migration, the device's status will be reported as Assigning

    • 重新预配并重置为初始配置:当与注册项关联的设备提交新的预配请求时,此策略将执行操作。Re-provision and reset to initial config: This policy takes action when devices associated with the enrollment entry submit a new provisioning request. 根据注册项配置,可将设备重新分配给其他 IoT 中心。Depending on the enrollment entry configuration, the device may be reassigned to another IoT hub. 如果设备正在更改 IoT 中心,则将删除初始 IoT 中心内的设备注册。If the device is changing IoT hubs, the device registration with the initial IoT hub will be removed. 向新的 IoT 中心提供预配设备时预配服务实例接收到的初始配置数据。The initial configuration data that the provisioning service instance received when the device was provisioned is provided to the new IoT hub. 迁移期间,设备的状态将报告为“正在分配” 。During migration, the device's status will be reported as Assigning.

  4. 单击“保存”,开始根据所作更改进行设备的重新预配 。Click Save to enable the reprovisioning of the device based on your changes.

    选择注册分配策略

发送来自设备的预配请求Send a provisioning request from the device

为根据前述部分中所作的配置更改重新预配设备,这些设备必须请求重新预配。In order for devices to be reprovisioned based on the configuration changes made in the preceding sections, these devices must request reprovisioning.

设备提交预配请求的频率由具体方案而定。How often a device submits a provisioning request depends on the scenario. 但是,建议设定计划,让设备在重启时向预配服务实例发送预配请求,同时还支持按需手动触发预配的方法However, it is advised to program your devices to send a provisioning request to a provisioning service instance on reboot, and support a method to manually trigger provisioning on demand. 此外,还可设置所需属性来触发预配。Provisioning could also be triggered by setting a desired property.

注册项上的重新预配策略将确定设备预配服务实例如何处理这些预配请求,以及是否应在重新预配期间迁移设备状态数据。The reprovisioning policy on an enrollment entry determines how the device provisioning service instance handles these provisioning requests, and if device state data should be migrated during reprovisioning. 单个注册和注册组可使用相同的策略:The same policies are available for individual enrollments and enrollment groups:

要通过示例代码了解如何在启动顺序期间发送来自设备的预配请求,请参阅自动预配模拟设备For example code of sending provisioning requests from a device during a boot sequence, see Auto-provisioning a simulated device.

后续步骤Next steps