Azure Iot Rest API Message from cloud to device

1k Views Asked by At

Get : https://myiot.azure-devices.net/devices/mydevice/messages/devicebound?api-version=2016-02-03

Authorization: SAS key

i am getting 204 No content response from above api while receiving message using postman request maker from cloud to device.When i send messages from device to cloud it is appearing in my iot hub but giving error 204 while receiving messages from cloud.

2

There are 2 best solutions below

5
On BEST ANSWER

First, if you haven't sent Cloud-To-Device messages and you get No content response(error code:204) from calling the GET api(https://myiot.azure-devices.net/devices/mydevice/messages/devicebound?api-version=2016-02-03). It is expected. It means the server has fulfilled the request, but there is no new information to send back.

Second, you want to receive the Device-To-Cloud message you have sent. It is unreachable. Because this GET api is used to receive Cloud-To-Device messages.

In short, Device-To-Cloud and Cloud-To-Device are different messaging primitives that Azure IoT hub provides to communicate with a device. And Device-To-Device communication that you want is not supported natively with Azure IoT Hub.

Finally, how to send Cloud-To-Device message?

For test purpose, you can send Cloud-To-Device message from Device Explorer. More detailed information you can reference here.

0
On

Yes, you can send cloud-to-device message POST : https://[iotHubName].azure-devices.net/devices/[deviceId]/messages/deviceBound?api-version=2020-09-30

Header must include Authorization like : SharedAccessSignature sr=webchatIOTHub.azure-devices.net&sig=lc7seNnczkq7Xj0IDSdFHshTTHEJUDt4y98e9Eoj%2B18%3D&se=1655587178&skn=iothubowner

For SAS (sharedAccessSignature) you have to run PowerShell CLI : az iot hub generate-sas-token -n [iotHubName]--du 3600000000

Also, you can view the RestAPI when you use the browser to send message to device enter image description here