Home > Back-end >  How to get (feedback)acknowledgments for messages sent to a device from IoT Hub in python?
How to get (feedback)acknowledgments for messages sent to a device from IoT Hub in python?

Time:03-09

I am able to send messages and reported-properties from iot hub to a simulated device through azure-iot-sdk-python. Now i wanna get acknowledgments (success,expired,rejected,purjed,DeliveryCountexceeded) for messages sent to the device/module from IoT Hub

ServiceClient.GetFeedbackReceiver method is available for .Net but i am not able to find a python sdk for getting message delivery feedback.

below is code used for sending c2d message

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)

i want to get a feedback when the message sending is failed.. please suggest me a solution.

Thanks in advance.. :)

CodePudding user response:

ServiceClient.GetFeedbackReceiver method is available for .Net but i am not able to find a python sdk for getting message delivery feedback.

You can try receive_feedback_notification() as available on cloud_to_device_messages_operations.py

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

Gets the feedback for cloud-to-device messages. See https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging for more information. This capability is only available in the standard tier IoT Hub. For more information, see 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>`

#Construct URL

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

If you want to test feedback notification, refer to test_iothub_http_runtime_manager.py

  • Related