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.
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.
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
Related
I am using service that can only send messages using webhook. The only thing I can set up in that webhook are HTTP endpoint, user name and password (you can see it on the screenshot below). I would like to send messages to my event hub, but I don't know how to find its HTTP endpoint. The only thing I could find was SAS Endpoint.
Event Hubs offers a REST API that allows you to perform a subset of the operations supported by its AMQP API. Publishing basic events via REST is possible and would use the endpoint: https://{servicebusNamespace}.servicebus.windows.net/{eventHubPath}/messages.
The full set of documentation for the REST API can be found here, and the specifics for sending events here.
I am trying to use Direct Method to invoke device OTA
The device I am using is Quectel EC21 and subscribe to the topic "$iothub/methods/POST/#"
When I Invoke the method in Azure IoT explorer,I always get the time out fail message that "message":"Timed out waiting for device to connect."
enter image description here
This error message confused me since I expect my device receive the method payload through MQTT from topic "$iothub/methods/POST/#" but I received nothing.
But at he same time, I can receive normal cloud to device MQTT message through topic "devices/deviceID/messages/devicebound/#"
So, is the Direct method connection and Iot hub connection are different connection?
After searching online and hint from Matthijs.
To make the direct method work, I found need to add api version in username field as below
For the Username field, use {iothubhostname}/{device_id}/?api-version=2018-06-30
I'm working on an IOT project, my hardware device is not able to read message header. So not able to send feedback to IOT hub, because i don't have the ETag. Is there any way to get a copy of the message that sent to the device from IOT hub., so that i can save the etag and and can provide to the device when it requests.
Or is there any other way to solve my issue.
Using this project here Im able to get an esp8266 to send messages to the Azure Iot hub, and I can read them with PowerBI. However, I would like to be able to use the device explorer Twin to send messages to the device.
I imagine that since the esp is sending messages to the Iot hub using an HTTP POST request, that I should be able to use an HTTP GET request to read the messages sent to the device when using the correct endpoint, outlined here.
Is this correct, or am I missing something? Doing this seems to only cause errors. If this is the right way, what would the format of a proper GET request be.
Receiving Cloud-to-Device message from Azure IoT hub via REST api you can use GET method.
Different from POST method you need use "devicebound" instead of "events" in Request URI part.
About Common parameters and headers, only Authorization header is required and it is the same with in the POST request.
There is no body required in GET request.
So, your GET request would look like this:
GET /devices/[Device ID]/messages/devicebound?api-version=2016-02-03 HTTP/1.1
Host: [IoTHubName].azure-devices.net
Authorization: SharedAccessSignature sr=[Shared Access Signature]
I'm trying to send a notification to my Android device using Azure Notification Hub.
When I use the Test Send functionality which is available in Azure Notification Hub it doesn't seem to care about the property "to" in the payload.
For example if I specify a fake deviceId like below I still receive a notification on my device.
{
"to" : "fW4Xab4JY3F:ERT91bHC4_hqzGj4AaHB_u1Dvzai6hFxyHFscgQ_TRAqWD1JGsE7FqFmknSuwlCEImmyn9R1gCDpsObZk33mpqaqdhWC_712AW2PI47ni15Jyrwq12xcSs9tZ784sLabz2I64J2LSe4q",
"notification": {
"title": "TITel",
"body": "Firebase Cloud Message"
}
}
If I do the same using Postman and calls the server side API of FCM I get a response saying InvalidRegistration if I enter a fake deviceId. And if I use a correct deviceId I get the notification as expected.
Anyone knows why the payload isn't working as I would expect it to within Azure Notification Hub?
Test Send is for testing only. The way it works is it sends notifications to 10 random devices. I guess the reason why it works for you from NH is probably because you have a few devices (or maybe even just 1 device) so all of them get notifications.
The reason why it doesn't work with FCM is because, as you mentioned, this is a fake ID. If you use an existing one, it should work.