Last active
November 28, 2016 21:40
-
-
Save darrenjrobinson/d3893f3552d2fd797cfd34215f62cd5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the PowerBI Powershell Module | |
Import-Module "D:\home\site\wwwroot\myapp\bin\PowerBIPS\1.2.0.8\PowerBIPS.psm1" -Force | |
# Add a reference to the AzureAD Active Directory Client Library | |
# Used by the PowerBI Powershell Module for AuthN to AAD. | |
Add-Type -Path 'D:\home\site\wwwroot\myapp\bin\AzureADPreview\2.0.0.33\Microsoft.IdentityModel.Clients.ActiveDirectory.dll' | |
# PowerBI ClientID, AAD Username and Password | |
# From Application Settings | |
$clientID = $env:PBIClientID | |
$username = $env:UID | |
$pwd = $env:CredKey | convertto-securestring -AsPlainText -Force | |
$credentials = New-Object System.Management.Automation.PSCredential $username,$pwd | |
# AuthN to PowerBi/AAD and get Authorization Token | |
$authToken = Get-PBIAuthToken -clientId $clientID -Credential $credentials | |
$authToken | |
# Sensor API URL's | |
$outdoorhumidityURL = $env:humidity | |
$outdoorTempURL = $env:OutdoorTemp | |
$IndoorTempURL = $env:IndoorTemp | |
$outdoorLuxURL = $env:Lux | |
# Date | |
# Get Date for where the sensors are, not the date where the Azure Function is running | |
$date = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([DateTime]::Now,"AUS Eastern Standard Time") | |
$strdate = $date.ToString("yyyy-MM-dd HH:mm:ss") | |
$strdate | |
# Outside Sensors | |
# Temp | |
$currentOutsideTemp = Invoke-RestMethod $outdoorTempURL | |
$currentOutsideTemp.celsius_degree | |
# Light | |
$currentOutsideLux = Invoke-RestMethod $outdoorLuxURL | |
$currentOutsideLux.lux | |
# Humidity | |
$currentOutsideHumidity = Invoke-RestMethod $outdoorhumidityURL | |
$currentOutsideHumidity.humidity | |
# Inside Sensors | |
# Temp | |
$currentInsideTemp = Invoke-RestMethod $IndoorTempURL | |
$currentInsideTemp.temperature | |
$currentInsideTemp = [math]::Round($currentInsideTemp.temperature) | |
Write-Output "Environmentals for: " $strdate | |
Write-Output "Temperature is: " $currentOutsideTemp.celsius_degree | |
Write-Output "Inside temperature is: " $currentInsideTemp.temperature | |
Write-Output "Humidity is: " $currentOutsideHumidity.humidity | |
Write-Output "Light is: " $currentOutsideLux.lux | |
# Outside PSObject with Env Data | |
$outsideEnvData = New-Object PSObject -prop @{ | |
DateTime = $strdate | |
OutsideTemperature = $currentOutsideTemp.celsius_degree | |
OutsideLight = $currentOutsideLux.lux | |
} | |
# Inside PSObject with Env Data | |
$insideEnvData = New-Object PSObject -prop @{ | |
DateTime = $strdate | |
InsideTemperature = $currentInsideTemp.celsius_degree | |
} | |
# Get the DataSet where we are going to send the data | |
$DataSet = Get-PBIDataSet -authToken $authToken -Name "Environment Sensors" | |
# Update the PowerBI Dataset with the latest readings. | |
$outsideEnvData | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName "Outside" -verbose | |
$insideEnvData | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName "Inside" -verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment