硬件开发者咨询:设备向Azure IoT Hub发送反馈的端点问题
Hey there! As someone who’s worked with IoT Hub’s HTTP endpoints for hardware integrations, let’s walk through how to handle your feedback needs and address the ETag issue you’re facing.
Sending Feedback via HTTP Endpoint
Since you only have HTTP available, here’s the step-by-step process to send feedback for cloud-to-device (C2D) messages:
Capture critical headers when receiving C2D messages:
When your device pulls a C2D message via the HTTP endpoint (https://{iot-hub-name}.azure-devices.net/devices/{device-id}/messages/devicebound?api-version=2020-09-30), IoT Hub returns key response headers you’ll need:iothub-locktoken: This unique identifier for the message is mandatory for sending feedback.ETag: A concurrency control value (not strictly required for basic feedback submission, but useful for validating message state if needed).
Construct the feedback request endpoint:
Use this dedicated URL tied to the specific C2D message:https://{iot-hub-name}.azure-devices.net/devices/{device-id}/messages/devicebound/{lock-token}/feedback?api-version=2020-09-30Replace
{lock-token}with theiothub-locktokenvalue you captured when receiving the message.Configure the request details:
- Method:
POST - Request body (JSON format) to define feedback status:
Valid{ "statusCode": 200, "description": "Message processed successfully" }statusCodevalues map to feedback types:200: Message completed successfully400: Message rejected (invalid content, unsupported format, etc.)404: Message abandoned (couldn’t process, will be removed from the queue)
- Authentication: Use the same SAS token or X.509 certificate your device uses to authenticate with IoT Hub.
- Method:
Addressing the ETag Read Issue
If your hardware’s HTTP client can’t access the ETag response header, don’t worry—you don’t need ETag to send basic feedback. The iothub-locktoken is the only required value for submitting feedback.
If you do need ETag for concurrency checks later, double-check your HTTP client’s header parsing logic: some clients normalize header names (e.g., converting ETag to etag), so try accessing the lowercase version of the header key.
Default Endpoint for Feedback
There isn’t a single "default endpoint" for all feedback requests—each feedback submission is tied to a specific C2D message, hence the need to include the unique lock-token in the endpoint URL. This ensures IoT Hub maps your feedback to the correct message in its queue.
内容的提问来源于stack exchange,提问作者Alex

