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
-
why i have a down vote here? Who ever has down voted please provide a reason – arun thatham Mar 14 '17 at 06:28
-
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 Mar 14 '17 at 09:45
-
It is a custum board. WeMos R1 D2 which is equipped with WiFi module ESP8266. It is REST on HTTP – arun thatham Mar 15 '17 at 09:49
3 Answers
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,381
- 2
- 20
- 44
-
1Hi raven, I am trying to send C2D message through API, The answer that you've shared does it serve the purpose or are there any updates for the same. – vishruti Apr 16 '20 at 15:26
-
1@vishruti, this answer is from two years ago. I don't now if azure has released an API yet for C2D messages. If no, the principle should be the same. Check the network request from your browser when you send a request from the Azure portal and you will be able to figured out. – raven Apr 17 '20 at 07:18
-
I tried your method but I am getting ("message": "Object reference not set to an instance of an object.") response in postman. Why do you think this error is occurring?? – vishruti Apr 17 '20 at 11:43
As Peter Pan said, there isn't a RESTful API for send C2D messages currently. However, you still have some other chooses.
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.
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.

- 172
- 1
- 9
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.
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.

- 23,476
- 4
- 25
- 43