2
votes

I explored on sending data from Device to Cloud using Azure REST Apis. It is working seamlessly without any issues. I'm not finding good articles on sending Cloud-to-Device messages to Arduino board using "Azure IoT Hub REST Apis". Could some one provide suggestions on this

3
why i have a down vote here? Who ever has down voted please provide a reasonarun thatham
Hi Arun, Which type of Arduino board you used? It's related to the REST API based on HTTP protocol or other protocols whether will be supported.Peter Pan
It is a custum board. WeMos R1 D2 which is equipped with WiFi module ESP8266. It is REST on HTTParun thatham

3 Answers

3
votes

You could also send the request as the azure portal does it. All C2D from AZ Portal are sent through this Endpoint https://main.iothub.ext.azure.com/api/Service/SendMessage/ and the payload is a json that look like this:

{
  "hostName": "iothub-hostname",
  "owner": "twinUpdate",
  "key": "key for the iothub",
  "deviceID": "your device on that hub",
  "body": "{\"test\": \"This is a test over postman\"}",
  "properties": "[]"
}

Keep in mind that you need to add an Authorization Header with valid Bearer token. You can get this when you log in to AZ Portal.

2
votes

As Peter Pan said, there isn't a RESTful API for send C2D messages currently. However, you still have some other chooses.

  1. Use Azure Function App. You can create a HTTP trigger Azure Function App to use as RESTful proxy, and run IoT Hub SDK on Azure Function App to send C2D messages.

  2. Use AMQP over WebSockets with 443 port if you cannot use 5671 port for AMQP to connect to IoT Hub on your service side. We have developed a web based IoT Hub devtool based on Rhea, and you can reference our code.

0
votes

According to the offical document Send and receive messages with IoT Hub, and after I reviewed the source codes of Azure IoT Hub for sending cloud-to-device message using different languages, there is no REST API to support on sending Cloud-to-Device messages. To send c2d message from application to Azure IoT Hub, the recommended protocol is AMQP and the simple way is using Azure IoT Hub SDK. That you can refer to the section Communication protocol, as below.

enter image description here

However, if you want to receive the c2d message from Arduino, you can refer to the section Cloud-to-device messages and use the REST API Receive Device Bound Notification on Arduino.