Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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
You can’t perform that action at this time.