Created
August 31, 2016 06:32
-
-
Save darrenjrobinson/db7b4f9d2b85e79ff396bec51e2a756b 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
$i=0 | |
Do { | |
$AuthResult = $AuthContext.AcquireToken($PbiResourceUrl,$ClientId, $UserCredential) | |
$authToken = $AuthResult.AccessToken | |
# Date | |
$date = get-date | |
$strdate = $date.ToString("yyyy-MM-dd HH:mm:ss") | |
# Outside | |
# Sensors | |
$currentOutsideTemp = Invoke-RestMethod https://iot.seeed.cc/v1/node/GroveTempHumD0/temperature?access_token=abcdefghijklmnop | |
$currentOutsideTemp.celsius_degree | |
$currentOutsideLux = Invoke-RestMethod https://iot.seeed.cc/v1/node/GroveDigitalLightI2C0/lux?access_token=abcdefghijklmnop | |
if (!$currentOutsideLux){ | |
$currentOutsideLux = 0 | |
} | |
else | |
{ | |
$currentOutsideLux = $currentOutsideLux.lux | |
} | |
$currentOutsideAirQ = Invoke-RestMethod https://iot.seeed.cc/v1/node/GroveAirqualityA0/quality?access_token=abcdefghijklmnop | |
$currentOutsideAirQ.quality | |
# Inside | |
# Sensors | |
$currentInsideTemp = $currentOutsideTemp.celsius_degree + (Get-Random -Minimum 1.1 -Maximum 5.93) | |
$currentInsideTemp = [math]::Round($currentInsideTemp,2) | |
$currentInsideLux = 0 | |
$currentInsideAirQ = 0 | |
# Outside PSObject with Env Data | |
$Outsideenvdata = New-Object PSObject -prop @{ | |
DateTime = $strdate | |
OutsideTemperature = $currentOutsideTemp.celsius_degree | |
OutsideLight = $currentOutsideLux | |
OutsideAirQuality = $currentOutsideAirQ.quality | |
} | |
# Inside PSObject with Env Data | |
$Insideenvdata = New-Object PSObject -prop @{ | |
DateTime = $strdate | |
InsideTemperature = '20' | |
InsideLight = $currentInsideLux | |
InsideAirQuality = $currentInsideAirQ | |
} | |
# Write Out the User data to PowerBI | |
$DataSet = Get-PBIDataSet -authToken $authToken -Name "Environment Sensors" | |
$Outsideenvdata | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName "Outside" -verbose | |
$Insideenvdata | Out-PowerBI -AuthToken $authToken -dataSetName $DataSet.name -tableName "Inside" -verbose | |
$i++ | |
Start-Sleep -s 60 | |
} while ($i -le 500 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment