Hello @Ying Min Teo ,
Adding to the above response posted by AshokPeddakotla-MSFT.
As suggested by Ashok in the above response, please try to use the Power Apps flow and make use of the Azure IoThub REST API to call the direct methods on the IoT Device.
Cloud-to-device communications guidance
IoT Hub provides three options for device apps to expose functionality to a back-end app:
- Direct methods for communications that require immediate confirmation of the result. Direct methods are often used for interactive control of devices such as turning on a fan.
- Twin's desired properties for long-running commands intended to put the device into a certain desired state. For example, set the telemetry send interval to 30 minutes.
- Cloud-to-device messages for one-way notifications to the device app.
IoT Hub gives you the ability to invoke direct methods on devices from the cloud. Direct methods represent a request-reply interaction with a device similar to an HTTP call in that they succeed or fail immediately (after a user-specified timeout). This approach is useful for scenarios where the course of immediate action is different depending on whether the device was able to respond.
Direct methods are implemented on the device and may require zero or more inputs in the method payload to correctly instantiate.
Invoke a direct method from a back-end app
To invoke a direct method from a back-end app use the Invoke device method REST API or its equivalent in one of the IoT Hub service SDKs.
Method invocation
Direct method invocations on a device are HTTPS calls that are made up of the following items:
The request URI specific to the device along with the API version:
https://fully-qualified-iothubname.azure-devices.net/twins/{deviceId}/methods?api-version=2021-04-12
The POST method
Headers that contain the authorization, content type, and content encoding.
A transparent JSON body in the following format:
{
"connectTimeoutInSeconds": 200,
"methodName": "reboot",
"responseTimeoutInSeconds": 200,
"payload": {
"input1": "someInput",
"input2": "anotherInput"
}
}
If the response is helpful, please click "Accept Answer" and upvote it. So that we can close this thread.