Created
November 28, 2016 11:31
-
-
Save darrenjrobinson/45cfc62392ca12da7173e2d6f792da47 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 Twitter Powershell Module | |
Import-Module "D:\home\site\wwwroot\myIOTFunction\bin\InvokeTwitterAPIs\2.3\InvokeTwitterAPIs.psm1" | |
# Twitter Account Details from Application Settings | |
$twitterID = $env:TwitterAccount | |
$twitterAccessToken = $env:AccessToken | |
$twitterAccessTokenSecret = $env:AccessTokenSecret | |
$twitterAPIKey = $env:APIKey | |
$twitterAPISecret = $env:APISecret | |
# Setup Twitter OAuth Hashtable | |
$OAuths = @{ 'ApiKey' = $twitterAPIKey; | |
'ApiSecret' = $twitterAPISecret; | |
'AccessToken' = $twitterAccessToken; | |
'AccessTokenSecret' = $twitterAccessTokenSecret} | |
# Sensor API URL's also from Application Settings | |
$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 | |
# Trace so we can see what is being retreived | |
Write-Output "Environmentals for: " $strdate | |
Write-Output "Outside temperature is: " $currentOutsideTemp.celsius_degree | |
Write-Output "Inside temperature is: " $currentInsideTemp.temperature | |
Write-Output "Humidity is: " $currentOutsideHumidity.humidity | |
Write-Output "Light is: " $currentOutsideLux.lux | |
# Tweet the Details | |
$tweet = "Env Update - Fermentation Coolroom: " + $currentInsideTemp.temperature +"degC. Brauhaus: "+ $currentOutsideTemp.celsius_degree + "degC. Humidity: " +$currentOutsideHumidity.humidity +"% recorded at " +$strdate | |
Write-Output $tweet | |
$Parameters = @{ 'status' = $tweet} | |
Invoke-TwitterRestMethod -ResourceURL 'https://api.twitter.com/1.1/statuses/update.json' -RestVerb 'POST' -Parameters $Parameters -OAuthSettings $OAuths |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment