2

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.. :)

giri rajh
  • 45
  • 4

1 Answers1

1

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://learn.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

Madhuraj Vadde
  • 1,099
  • 1
  • 5
  • 13
  • when i try below code i am facing below error – giri rajh Mar 10 '22 at 04:40
  • `from azure.iot.hub.iothub_http_runtime_manager import IoTHubHttpRuntimeManager iothub_http_runtime_manager = IoTHubHttpRuntimeManager.from_connection_string(CONNECTION_STRING) feedback = iothub_http_runtime_manager.receive_feedback_notification() print ( 'feedback message: {0}'.format(feedback) )` – giri rajh Mar 10 '22 at 04:41
  • error: File "/home/giri/.local/lib/python3.7/site-packages/azure/iot/hub/protocol/operations/cloud_to_device_messages_operations.py", line 126, in receive_feedback_notification raise HttpOperationError(self._deserialize, response) msrest.exceptions.HttpOperationError: Operation returned an invalid status code 'Bad Request'` – giri rajh Mar 10 '22 at 04:42
  • You can refer to similar errors and their solutions on GitHub: https://github.com/MicrosoftDocs/azure-docs/issues/62373 and https://github.com/Azure/azure-iot-sdk-python/issues/825 – Madhuraj Vadde Mar 10 '22 at 07:03
  • All C2D message feedback endpoints are returning Bad Request at the moment :-( – Solar.gy Apr 27 '22 at 14:49