There are several ways to communicate from an IoT device to the Cloud using Azure IoT Hub. You can send information as telemetry, or you can update a reported property in the device twin. You get an ACK that your message has been transferred. In the Cloud, you can route your message to several Azure resources such as a Service Bus Queue or an Event Hub, and you can trigger an Azure Function to start when such a message is received. You can also route a Twin Property changed in the same way. If you want to reply from the Cloud to your device, you can update a Desired Twin property or use a direct method call to the device. Updating a desired property is an asynchronous operation; hence, even if the device is offline, it gets the property value when the device reconnects. A direct method is a synchronous operation, a request-reply; hence you can call it from the Cloud and get an answer from the device.
You can always use other communication channels and mechanisms such as calling a REST API from the device or using a service such as SignalR. Still, I recommended the Azure IoT Hub as the management and communication mechanism.
IoT hub: Device-to-cloud: Request and response
Hello,
i'm a beginner in azure and i want to know if it is possible to send a request from a IoT device to the IoT hub and receive the response?
For example, i want to know the temperature of a room and the data is stored in a Azure SQL DB. Then i send the request to the IoT hub and get the data from the db.
It is important that the device is the actor not the cloud.
Azure IoT Hub
3 answers
Sort by: Most helpful
-
Alon Fliess 261 Reputation points
2021-12-12T21:57:23.297+00:00 -
Sander van de Velde | MVP 36,761 Reputation points MVP Volunteer Moderator
2021-12-12T22:42:09.323+00:00 Hello anonymous user-5773 ,
As @Alon Fliess already mentioned, combining secure device-to-cloud communication with IoT Hub messages routing to e.g. an Azure Function and sending a response back using cloud-to-device communication using the same IoT Hub is a common IoT pattern.
Please check out this learning path to learn about the capabilities of the IoT Hub and this learning path regarding message processing in the cloud.
This module tells more regarding cloud-to-device messaging.
On Github, there are multiple programming examples available for several programming languages. Here are some examples in C#.
-
Christophe Gigax 0 Reputation points MVP
2024-09-23T12:26:26.8466667+00:00 Hello,
As mentionned above, you can achieve Request-Response pattern from Cloud to device using Iot Hub direct methods - but not the contrary where the device is the initiator of the request.
Event Grid MQTT supports that scenario with MQTT v5 Request-Response pattern : https://learn.microsoft.com/en-us/azure/event-grid/mqtt-request-response-messages