locked
Unable to Recieve C2D messages sent from a rest client on REST Client RRS feed

  • Question

  • I need to do device to device communication using Rest Client.

    The problem i am facing is that, when i send a message from device to cloud using REST client i get a 204 response which is successful message.

    But i am unable to receive this message when i try to get it back using GET URL using REST client.

    One thing i want to mention that, if i use device explorer to monitor my device , i receive the messages in it.

    Kidly help,

    the links i am using are as follows

    for D2C>

    POST : https://YBIOT.azure-devices.net/devices/MyDevice/messages/events?api-version=2016-02-03

    for C2D>

    GET : https://YBIOT.azure-devices.net/devices/MyDevice/messages/devicebound?api-version=2016-02-03

    Regards

    Faizan Latif Qureshi

    Sunday, December 25, 2016 4:43 PM

All replies

  • Hi,

    The current version of the Azure IoT Hub doesn't have built-in a direct device-to-device communications using a REST API. To achieve this thing, it is necessary to built on the server side some "worker role" or Azure Function. 

    I do recommend to study the following link: Reference - IoT Hub endpoints, where is described, that:

    - Device endpoints are exposed using MQTT v3.1.1, HTTP 1.1, and AMQP 1.0 protocols. Note that AMQP is also available over WebSockets on port 443.

    - Service endpoints (for device communications) are currently only exposed using the AMQP protocol, except for the method invocation endpoint that is exposed via HTTP 1.1.

    In other words, the device can pushed a message via the telemetry endpoint to the custom Service Bus Queue (via the Azure IoT Hub Routing). The reply message to the device must be done with AMQP to the service-face endpoint, where this message is internally forwarded to the device-face queue by Azure IoT Hub. Now, the device can pulled out the message from this C2D queue using a GET REST API.

    Another technique of the D2D communications can be found in the article: Device to Device Communication with Azure IoT Hub.

    Note, that the above solutions are related for device-to-device communications in the async and disconnected manner.  

    In the case, when the device-to-device communications must be in the sync manner, the Azure IoT Hub today offers using a direct method call, where the invoker can used the REST API, but the method receiver/responder must be handled by MQTT.

    See, the article Windows IoT Core and M2MQTT for more details how to use this nuget package in the UWP application.

    In the conclusions, today the Azure IoT Hub has built-in the device-to-device communication using the REST API only for invoker (consumer) of the direct method, the other side such as device method must be implemented by MQTT protocol.

    If this is your case, for instance, the multiple devices "talk" to one device (let mi say master, where can be used MQTT), than the solution is straightforward.

    Btw. The Device Explorer Twin utility is implemented for service-face endpoints. It is using a nuget package Service SDK for Azure IoT Devices

    Thanks

    Roman





    • Edited by Roman Kiss Sunday, December 25, 2016 8:31 PM
    Sunday, December 25, 2016 8:14 PM
  • Thank you for the response, basically i need to connect esp8266 with android device with azure backend.

    Can you provide any related material for help?

    Tuesday, December 27, 2016 7:13 AM
  • Hi,

    - I do recommend the following links:

    Device-facing:

         Starter-kits connected to the Azure IoT Hub

         Using the Azure IoT SDK in Android  

         ESP8266, Arduino & Azure IoT Hub 

         IoT Hub native MQTT support - disqus   

         MQTTBox Client - tester

    Service-facing (Azure IoT Hub):

        Send and receive messages with IoT Hub

        Process IoT Hub device-to-cloud messages using routes.

        Azure Functions

    - In the case to stay with the Http protocol on the device-facing side, the following screen snippets show a generating (simulating) end-to-end process of the C2D message by Device Explorer Twin, getting this message by GET REST API, completed (ack) this message a finally screen snippet of the feedback message:

    1. Generating C2D Message

     

    2. Get C2D Message

    Note: The C2D message is locked (for 60 seconds) after the above request, therefore calling it again will return always a status 204:No Content until expiring a locking time. The message must be completed/rejected/abandoned before its TTL time in the queue.

    3. Complete C2D Message

    4. Send Feedback Message

    Thanks

    Roman



    • Edited by Roman Kiss Wednesday, December 28, 2016 8:32 PM
    Wednesday, December 28, 2016 8:09 PM