locked
GET HTTP Request from ESP8266 RRS feed

  • Question

  • Im trying to achieve Bi-directional Communication with an ESP8266 by communication over the IoT hub using HTTP/REST. I've used the following project as a starting point, and can successfully send a POST request to the IoT hub, and view it using the Device Explorer and PowerBI.

    Starting point project: https://github.com/gloveboxes/Arduino-ESP8266-Secure-Azure-IoT-Hub-Client

    However, I am having difficulty when trying to read Cloud-to-device messages (Which I am sending using the device explorer).

    This is the POST request I am using that successfully publishes the device information to the IoT hub after establishing a TLS connection with Azure:

    POST /devices/[Device ID]/messages/events?api-version=2016-02-03 HTTP/1.1
    Host: Dehumidifers.azure-devices.net
    Authorization: SharedAccessSignature sr=[Shared Access Signature]
    Content-Type: application/atom+xml;type=entry;charset=utf-8
    Content-Length: 177

    {"Dev":"[Device ID]","Utc":"2016-12-13T22:33:04","Celsius":60.00,"Humidity":30.00,"Setpoint":70,"State":0,"Geo":"West US","WiFi":0,"Mem":18728,"Id":2}

    Since reading the messages sent to a device requires a different endpoint, I assume it would look something like this:

    GET /devices/[Device ID]/messages/devicebound/# HTTP/1.1
    Host: Dehumidifers.azure-devices.net
    Authorization: SharedAccessSignature [SAS]

    However this doesn't seem to be working. If using a GET request over HTTP is the correct method to receive C2D messages, then what is the format of a proper GET request to Azure? What other headers are necessary for a successful request?


    • Edited by OEMSolutionsDev Thursday, December 15, 2016 5:35 PM Modified GET request to include Host and Authorization
    • Moved by IoTGirlMicrosoft employee Sunday, December 18, 2016 6:14 PM Azure IoT not Windows IoT
    Thursday, December 15, 2016 4:52 PM

Answers

  • Hi,

    - have a look at the Device Messaging REST APIs for details.

    the following screen snippet shows my example of the Get C2D Message sent it by the Device Explorer Twin tool:

    Note, that your device (receiver of the C2D) needs to send a Complete/Reject/Abandon message, see more details here.

    Thanks

    Roman 




    Thursday, December 15, 2016 5:52 PM

All replies

  • Hi,

    - have a look at the Device Messaging REST APIs for details.

    the following screen snippet shows my example of the Get C2D Message sent it by the Device Explorer Twin tool:

    Note, that your device (receiver of the C2D) needs to send a Complete/Reject/Abandon message, see more details here.

    Thanks

    Roman 




    Thursday, December 15, 2016 5:52 PM
  • Thank you, that's gotten me as far as being able to get a response at least. I'm currently getting back the message:


    {"Message":"ErrorCode:IotHubNotFound;Unauthorized","ExceptionMessage":"Tracking ID:[Tracking ID]-G:8-TimeStamp:12/16/2016 00:28:14"}

    Could this perhaps be because of an incorrect SAS, or would that message be caused by something else? thank you.

    Friday, December 16, 2016 5:11 PM
  • - try to use some REST client, for example Advanced REST client with the Device Explorer to simulate the C2D messaging. The SAS can be generated by Device Explorer from Configuration Tab.

    Thanks

    Roman



    • Edited by Roman Kiss Friday, December 16, 2016 6:49 PM
    Friday, December 16, 2016 6:48 PM
  • Thank you, I've got it up and running now!
    Monday, December 19, 2016 11:15 PM