In 2021, each month there will be a monthly blog covering the webinar of the month for the low-code application development (LCAD) on Azure solution. LCAD on Azure is a solution to demonstrate the robust development capabilities of integrating low-code Microsoft Power Apps and the Azure products you may be familiar with.
This month’s webinar is “Unlock the Future of Azure IoT through Power Platform.” In this blog, I will briefly recap LCAD on Azure, provide an overview of IoT on Azure and Azure Functions, how to pull an Azure Function into Microsoft Power Automate, and how to integrate your Power Automate flow into Power Apps.
What is LCAD on Azure?
LCAD on Azure was created to help developers build business applications faster with less code. Utilizing Microsoft Power Platform, and more specifically Power Apps, helps developers scale and extend their Power Apps with Azure services. For example, a pro developer who works for a manufacturing company would need to build a line-of-business (LOB) application to help warehouse employees track incoming inventory. That application would take months to build, test, and deploy. Using Power Apps, it can take only hours to build—saving time and resources.
However, say the warehouse employees want the application to automatically place procurement orders for additional inventory when current inventory hits a determined low. In the past, the development team would require another heavy lift to rework their previous application iteration. Due to the integration of Power Apps and Azure, a professional developer can build an API in Visual Studio (VS) Code, publish it to their Azure portal, and export the API to Power Apps, integrating it into their application as a custom connector.
Afterward, that same API is reusable indefinitely in the Power Apps’ studio for future use with other applications, saving the company and developers more time and resources.
IoT on Azure and Azure Functions
This webinar aims to understand how to use Azure IoT Hub and Power Apps to control an IoT device. To start, one would write the code in Azure IoT Hub to send commands directly to your IoT device. In this webinar, Samuel wrote in Node for Azure IoT Hub and wrote two basic commands: toggle fan on and off.
The commands are sent through the code in Azure IoT Hub, which at first run locally. Once tested and confirmed to be running correctly, the next question is how can one rapidly call the API from anywhere across the globe? The answer is to create a flow in Power Automate and connect that flow to Power Apps, which will be a complete dashboard that controls the IoT device from anywhere in the world. To accomplish this task, you have to first create an Azure Function, which will then be pulled into Power Automate using a Get function creating the flow.
Once you’ve built the Azure Function, run and test it locally first, test the on and off states through the Azure Function URL. To build a trigger for the Azure Function, in this case, a Power Automate flow, you need to create an Azure resources group to check the Azure Function and test its local capabilities. If the test fails it could potentially be that you did not create or have an access token for the IoT device. To connect a device, IoT, or otherwise to the cloud, you need to have an access token.
In the webinar, Samuel added two application settings to his function for the on and off commands. After adding these access tokens and adjusting the settings of the IoT device, Samuel was able to run his Azure Function successfully.
Azure Function automated with Power Automate
After building the Azure Function, you can build your Power Automate flow to start building your globally accessible dashboard to operate your IoT device. Samuel starts by building a basic Power Automate framework, then flow, and demonstrates how to test the flow once complete. He starts with an HTTP request and implements a Get command. From there, it is a straightforward process to test and get the IoT device to run.
Power Automate flow into Power Apps
After building your Power Automate flow, you develop a simple UI to toggle the fan on and off. Do this by building a canvas Power App and importing the Power Automate flow into the app.
To start, create a blank canvas app, and name it. In the Power Apps ribbon, you select button, and pick the button’s source, selecting Power Automate and add a flow. Select the flow that is connected to the Azure IoT device—its name should be reflected in the selection menu. If everything is running correctly, your IoT device will turn on. In the webinar, Samuel is running out of time, so he creates a new Power Automate flow, which he imports into the canvas app.
Learn more
- Make sure to watch the webinar “Unlock the Future of Azure IoT through Power Platform” to learn more about Azure IoT and how to import Azure Functions into your Power Apps.
- Additionally, there will be a low-code application development on Azure Learn Live session during Microsoft Build, covering the new .NET x Power Apps learning path, integrations with Azure Functions, Visual Studio, and API Management.