如何在 python 中获取从 IoT 中心发送到设备的消息的(反馈)确认?

How to get (feedback)acknowledgments for messages sent to a device from IoT Hub in python?

我能够通过 azure-iot-sdk-python 从物联网集线器向模拟设备发送消息和报告属性。 现在我想收到来自 IoT Hub

发送到 device/module 的消息的确认 (success,expired,rejected,purjed,DeliveryCountexceeded)

ServiceClient.GetFeedbackReceiver 方法可用于 .Net,但我找不到 python sdk 来获取消息传递反馈。

下面是用于发送c2d消息的代码

from azure.iot.hub import IoTHubRegistryManager
CONNECTION_STRING = ""
DEVICE_ID = ""

registry_manager = IoTHubRegistryManager(CONNECTION_STRING)
data = "Hello.. message from cloud"
props={}
registry_manager.send_c2d_message(DEVICE_ID, data, properties=props)

我想在消息发送失败时得到反馈..请给我一个解决方案。

提前致谢..:)

ServiceClient.GetFeedbackReceiver 方法可用于 .Net,但我找不到 python sdk 来获取消息传递反馈。

您可以尝试 receive_feedback_notification() cloud_to_device_messages_operations.py

def receive_feedback_notification(self, custom_headers=None, raw=False, **operation_config):

获取 cloud-to-device 条消息的反馈。 请参阅 https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging 更多信息。此功能仅在标准层 IoT 中心可用。有关详细信息,请参阅 Choose the right IoT Hubtier

:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response 
:param operation_config: :ref:`Operation
configuration overrides<msrest:optionsforoperations>`. 
:return: None
or ClientRawResponse if raw=true 
:rtype: None or
~msrest.pipeline.ClientRawResponse 
:raises:
:class:`HttpOperationError<msrest.exceptions.HttpOperationError>`

#构建URL

url = self.receive_feedback_notification.metadata["url"]

如需测试反馈通知,请参考test_iothub_http_runtime_manager.py