如何使用python iot Hub device SDK从物联网设备中检索完整的孪生设备

2024-04-28 11:47:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python编写一个带有iot集线器设备SDK的azureiot设备应用程序。

我在应用程序中使用device twin-state的所需属性,并在来自azure的device twin changes上通过device_twin_callback()更新它们。 但是,当我重新配置我的设备时(例如重新启动时),我会得到DPS中指定的初始设备双工状态,而不是物联网集线器的当前双工状态。

在使用python中的IoT集线器设备SDK重新配置时,是否有方法检索当前的设备孪生状态?

我想避免的一个解决方案是将设备的最后状态保存在文件中。


Tags: 应用程序属性device状态callbacksdktwinazure
1条回答
网友
1楼 · 发布于 2024-04-28 11:47:23

Is there a way to retrieve the current device twin state on reprovisioning with the IoT Hub Device SDK in python?

你的问题不是准确。没有其他方法可以检索当前的设备孪生状态,只有restapi ^{}及其相关的Python API ^{}。在

重新配置时包含在设备状态数据中的设备孪生设备仅取决于^{}的选择,如下所示。在

  • Re-provision and migrate data: This policy is the default for new enrollment entries. This policy takes action when devices associated with the enrollment entry submit a new request (1). Depending on the enrollment entry configuration, the device may be reassigned to another IoT hub. If the device is changing IoT hubs, the device registration with the initial IoT hub will be removed. The updated device state information from that initial IoT hub will be migrated over to the new IoT hub (2). 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 (1). Depending on the enrollment entry configuration, the device may be reassigned to another IoT hub. If the device is changing IoT hubs, the device registration with the initial IoT hub will be removed. The initial configuration data that the provisioning service instance received when the device was provisioned is provided to the new IoT hub (2). During migration, the device's status will be reported as Assigning. This policy is often used for a factory reset without changing IoT hubs.

  • Never re-provision: The device is never reassigned to a different hub. This policy is provided for managing backwards compatibility.

使用Azure IoT SDK for Python,重新配置策略由^{}对象的参数update_hub_assignment和{}设置,请参阅下面的说明。在

The behavior of the service when a device is re-provisioned to an IoT hub.
All required parameters must be populated in order to send to Azure.
:param update_hub_assignment: Required. When set to true (default), the
 Device Provisioning Service will evaluate the device's IoT Hub assignment
 and update it if necessary for any provisioning requests beyond the first
 from a given device. If set to false, the device will stay assigned to its
 current IoT hub. Default value: True .
:type update_hub_assignment: bool
:param migrate_device_data: Required. When set to true (default), the
 Device Provisioning Service will migrate the device's data (twin, device
 capabilities, and device ID) from one IoT hub to another during an IoT hub
 assignment update. If set to false, the Device Provisioning Service will
 reset the device's data to the initial desired configuration stored in the
 corresponding enrollment list. Default value: True .
:type migrate_device_data: bool

并且ReprovisionPolicy对象是在^{}^{}对象中初始化的属性。在

因此,请尝试更改update_hub_assignment和{}的组合,以实现您的需求。否则,缓存历史数据的解决方案是唯一的解决方案。在

相关问题 更多 >