Skip to content

Instantly share code, notes, and snippets.

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