Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### ALARM TRIGGER SCRIPT
- write-host starting script
- install-Module Microsoft.PowerShell.IoT
- "Set Alarm For Powerup"
- set-gpiopin -id 3 -value High
- sleep 2
- set-gpiopin -id 3 -value Low
-
- function post-gmmessage {
- param([string]$text)
- $text = $text.replace(" ","+")
- $posturl = 'https://api.groupme.com/v3/bots/post?bot\_id=<OUR\_BOT\_ID>'
- $posturladd = $posturl + $text
- $outnullvar = Invoke-WebRequest -Uri $posturl$text -Method Post
- }
-
- function get-gmmessage {
- $apiKey = "?token=<OUR\_SECURITY\_TOKEN>"
- $resource = "https://api.groupme.com/v3/groups/<OUR\_GROUP\_ID>"
- $var = Invoke-RestMethod -Uri $resource$apikey
- $var.response.messages.preview.text
- }
- "Variables Collected"
- DO {
- "Collecting Messages"
- $cmessage = get-gmmessage
- if ( $cmessage -eq "#EXIT" ) { EXIT }
- if ( $cmessage -like "*#911*" ) {
- $cmessage = $cmessage.replace("#","")
- $post = "Confirm Dispatch Alarm at Station $cmessage"
- "Dispatch"
- post-gmmessage -text $post
- "Pin Set ALARM"
- set-gpiopin -id 3 -value High
- sleep 2
- set-gpiopin -id 3 -value Low
- sleep 8
- set-gpiopin -id 3 -value High
- sleep 2
- set-gpiopin -id 3 -value Low
- "Alarm Silence"
- "Waiting for message change from current"
- }
- "Neutral State"
- sleep 10
- $failsafe = (Get-Date -Format yyMMddHHmm).ToString()
- $failsafe | Set-Content /<FOLDER>/failsafe.log -Encoding ascii
- } until ( $never -eq $true )
- ### ALARM TRIGGER SCRIPT END
- ### Event EMail
- "Starting"
- function send-gmail {
- param([string]$subject)
- $password = "<mypassword>" | ConvertTo-SecureString -asPlainText -Force
- $username = "<myemail>@gmail.com"
- $credential = New-Object System.Management.Automation.PSCredential($username,$password)
- $From = ["](mailto:"kd0jar@gmail.com)<myemail>@gmail.com"
- $To = ["](mailto:"kd0jar@gmail.com)<myemail>@gmail.com"
- $Body = "Automated Message"
- $SMTPServer = "smtp.gmail.com"
- $SMTPPort = "587"
- Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential ($credential)
- }
-
- sleep 10
- if (( Test-Connection -Count 1 -ComputerName <ourwebsite> -Quiet) -eq $true ) {send-gmail -subject "Startup Detected"}
- $count = 0
- $success = 0
- do {
- if( (Test-Connection -Count 1 -ComputerName <ourwebsite> -Quiet) -eq $false ) {
- $count = $count + 1
- $success = 0
- } elseif (( Test-Connection -Count 1 -ComputerName <ourwebsite> -Quiet) -eq $true ) {
- if ( $count -gt 100 ) { send-gmail -subject "$count failed ping on connection re-established" }
- $count = 0
- }
- if ( $count -gt 1000 ) { Restart-Computer -Force }
- if ( $success -gt 10000 ) { send-gmail -subject "Still going strong 10k" ; $success = 0 }
- $success = $success + 1
- $failsafe = (Get-Date -Format yyMMddHHmm).ToString()
- $failsafecheck = Get-Content /<FOLDER>/failsafe.log
- if ( ( $failsafe - 10 ) -gt $failsafecheck ) { send-gmail -subject "Runscript stopped running" ; Restart-Computer -Force }
- sleep 5
- } until ( $never -eq $true )
- ### Event EMail
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement