Universal Energy Monitoring With Azure
Monitoring energy usage of any device via Azure using a simple Arduino based Energy Monitor
Pre-requisite
Windows PowerShell (>= 5.1, get-host|Select-Object version
to get the version)
- You need an Azure Subscription and need to have Contributor role on the subscription. You should also have up to date versions of Visual Studio and .NET Core installed.
- Azure PowerShell Module
- Install Azure Powershell
- Go to Powershell (Admin-role):
Install-Module -Name AzureRM -AllowClobber Install-Module -Name AzureAD -AllowClobber Install-Module -Name Invoke-MsBuild -AllowClobber
- A computer with Git client installed.
- Install Visual Studio 15.5 (and up)
Deploying the Azure Components to your Azure Subscription:
- Clone the repo:
git clone https://github.com/conork20/UniversalEnergyMonitorWithAzure.git
cd UniversalEnergyMonitorWithAzure\AzureDeployment
- Deploy new service with PowerShell
Launch new PowerShell session and connect to Resource Manager and Azure Active Directory with the account that be used as deployment admin.
Connect-AzureRmAccount
Connect-AzureAD
Select subscription where you want to deploy resources.
Set-AzureRmContext -SubscriptionId <SubscriptionId>
Create new resource group and create core resources of the service.
.\New-ServiceResources.ps1 -ResourceGroupName <group>
Configuring IoT Central to Receive Telemetry from the Energy Monitor
- First, create a Device Template in your IoT Central Instance to match the telemetry the Arduino device will be sending in. Follow the steps outlined Set up a device template. Configure the device telemetry points of power and kwh as time series telemetry datapoints as such:
-
Now add under Device Explorer, add a device of the Energy Monitor Device Template which to couple the physical energy monitor with to send in and monitor it's energy reading data:
-
With the IoT Central device instance created, the last step is to Generate the connection string which you will configure in the code running on the Arduino so it can securely send it's sensor data into IoT Central. To do this, follow steps 1 through 7 in Generate the connection string. When you have the device connection string, you're ready to start sending in data, either from the simulated device service, or from the real Arudiono energy monitor in the following two sections.
Configuring a Simulated Energy Monitor to send in Data to IoT Central
- If not already done, create an Azure Function App. See steps here
- Update Application Settings in Portal for
voltage
to any integer value,amperage
to any double value, andconnectionString
to your device's Iot Hub connection string. You can determine your connection string using this tool. - Publish SyntheticSensorMessenger to your Azure Function App. See Steps for Visual Studio Code or Steps for Visual Studio
Configuring the Real Arduino Energy Sensor to send in telemetry Simulated Device
Run through the steps in Setting up the Arduino sensor