Created
March 9, 2017 08:59
-
-
Save chowmean/6e6b8fd896f480cfbbead1c9eb6feee1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 RPi.GPIO as GPIO | |
| import time | |
| from fabric.api import * | |
| env.hosts = [ | |
| "HOST" | |
| ] | |
| # Set the username and password for ssh | |
| env.user = "USERNAME" | |
| env.password = "PASSWORD" #avoid this in case of your ssh key is already added to the machine. | |
| def shutdown_all(): | |
| run("shutdown -h now") | |
| if __name__ == "__main__": | |
| current_state = 0 | |
| total_inactive = 0 | |
| pir_sensor = 13 #sensor pin number | |
| GPIO.setmode(GPIO.BOARD) | |
| GPIO.setup(pir_sensro,GPIO.IN) | |
| while(True): | |
| time.sleep(1) | |
| current_state = GPIO.input(pir_sensor) | |
| if current_state: | |
| total_inactive = 0 | |
| else: | |
| total_inactive = total_inactive + 1 | |
| if (total_inactive == 100): | |
| shutdown_all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment