Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created November 28, 2016 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/45cfc62392ca12da7173e2d6f792da47 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/45cfc62392ca12da7173e2d6f792da47 to your computer and use it in GitHub Desktop.
# 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