I have been reading the documentation of this new SaaS offering, but I do not see any mention about being able to send a message to the device, eg: to switch ON/OFF an equipment.
https://docs.microsoft.com/en-us/azure/iot-central/tutorial-add-device
I do see there is a provision to change the settings of the device, by being able to alter device-twin. Also, I read there is a way to send an "echo" to the device. But, these don't serve my exact purpose.
So, is there a way I can send a C2D message, using the connection-string, which can be built using the routine-? https://docs.microsoft.com/en-us/azure/iot-central/tutorial-add-device#prepare-the-client-code
I would like to send this C2D through an AzureFunction, but it would be good to know if this can be somehow integrated into the IoT-Central UI.
Any other inputs to achieve my requirement(switch ON/OFF an equipment) would be a great help too!
Thanks and regards,
As I mentioned in my comment, the Azure IoT Central has a full control over the internal IoT Hub service-facing endpoint. However, there is a way, where the Azure IoT Central allows a limited access to this service-facing endpoint and using a REST API to handle a device twin and invoking a Direct Method on the device.
The following are steps how to obtain a sas token for authorization header needed for REST Api calls:
Get the Access Token from your Azure IoT Central application.
the format is:
Note, that the appId is showing an application id of your Azure IoT Central application
Call the REST POST request to obtain an iothubTenantSasToken.sasToken
The response has the following format:
The sasToken for our service-facing endpoint calls is:
Now, we can use some Azure IoT Hub REST APIs, basically the calls with the twins in the uri path, such as:
https://docs.microsoft.com/en-us/rest/api/iothub/service/gettwin
https://docs.microsoft.com/en-us/rest/api/iothub/service/updatetwin
https://docs.microsoft.com/en-us/rest/api/iothub/service/replacetwin
https://docs.microsoft.com/en-us/rest/api/iothub/service/invokedevicemethod
Example for invoking a Direct Method on the device1:
Example of updating a device twin tags property:
Note, that the sasToken expiry time is 60 minutes. I do recommend to cache the response object from the step 2. and refreshing based on the expiry time.
UPDATE:
The following are steps for using an IoT Central access token for handling a device twins and device direct method within the azure function.
Add this access token to your function application settings. In this example, the App Setting Name is used AzureIoTCAccessToken. Note, that this access token can be stored in the Azure Key Vault, see more details here.
Create HttpTrigger function in your Function App.
Replace run.csx with the following code:
Note:, The above implementation is based on the generated access token by your IoT Central application like it has been recently released for general availability, see here. In the case of the changing a format, etc. all clients, testers, etc. included the above solution will be impacted.
For your specific use case, the only way to do this today is to trigger a Logic App workflow using its HTTP endpoint from the Azure Functions. In the Logic app, you can build a workflow using the Azure IoT Central connector that updates device properties and settings.
We are working on APIs in IoT Central that can light up use cases like yours, so stay tuned!
You can try using Settings there is a setting type called "Toggle". In order to implement it, you can go to your IoT Central Application from the Azure Portal. Then:
Go to Device Explorer tab
Select a device
If you are looking into doing it at scale you could Create and Run a Job
In IoT Central you can manage your connected devices at scale using jobs. The jobs functionality enables you to perform bulk updates to device properties, settings, and commands.