Unlock the Future of Azure IoT through Power Platform

This post has been republished via RSS; it originally appeared at: Azure Developer Community Blog articles.

Azure IoT Gif maker.gif

 

Overview 

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 Low-code application development on Azure, provide an overview of IoT on Azure and Azure Functions, how to pull an Azure Function into Power Automate, and how to integrate your Power Automate flow into Power Apps.

 

What is Low-code application development on Azure?   

Low-code application development (LCAD) on Azure was created to help developers build business applications faster with less code. 

Leveraging the Power Platform, and more specifically Power Apps, yet helping them 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 hours to build, saving time and resources.   

However, say the warehouse employees want the application to place procurement orders for additional inventory automatically when current inventory hits a determined low.

 

In the past that would require another heavy lift by the development team 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.

 

Afterwards, that same API is re-usable 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 

The goal of this webinar is to understand how to use 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 IoT Hub, and wrote two basic commands, toggle fan on, and off.

  

The commands are sent via the code in Azure IoT Hub, which at first run locally. Once tested and confirmed to be running properly 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 a Power App, 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 via the 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 successfully run his Azure Function.

 

Azure Function automated with Power Automate 

After building the Azure Function, you now 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 a 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 properly your IoT device will turn on.

 

FYI in the webinar Samuel is running out of time, so he creates a new Power Automate flow, which he imports into the canvas app.

 

Summary 

Make sure to watch the webinar 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 Build, covering the new .NET x Power Apps learning path, covering integrations with Azure Functions, Visual Studio, and API Management.

 

Lastly, tune in to the Power Apps x Azure featured session at Build on May 25th, to learn more about the next Visual Studio extensions, Power Apps source code, and the ALM accelerator package. Start registering for Microsoft Build at Microsoft Build 2021. 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.