├── Electrical_Diagram.jpg ├── .gitattributes ├── Light.py ├── .gitignore └── Door_Control.py /Electrical_Diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericescobar/Chicken_Door/HEAD/Electrical_Diagram.jpg -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Light.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import RPi.GPIO as GPIO 3 | import time 4 | import signal 5 | import sys 6 | import httplib, urllib #for Push Notifications 7 | import subprocess 8 | 9 | 10 | #Setting up Board GPIO Pins 11 | GPIO.setmode(GPIO.BOARD) 12 | GPIO.setup(38,GPIO.OUT) 13 | GPIO.setup(40,GPIO.OUT) 14 | #Clean kill of script function (Stops Motor, cleans GPIO) 15 | def Safe_Kill(): 16 | print 'Performing safe shutoff!' 17 | GPIO.output(38,False) 18 | GPIO.output(40,False) 19 | GPIO.cleanup() 20 | sys.exit('Lights out!') 21 | print 'Light on!' 22 | GPIO.output(38,False) 23 | GPIO.output(40,True) 24 | time.sleep(2) 25 | cmd = "fswebcam -q -r 640x480 Zip.jpg" 26 | subprocess.Popen(cmd , shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 27 | time.sleep(2) 28 | Safe_Kill() 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | 56 | # ========================= 57 | # Operating System Files 58 | # ========================= 59 | 60 | # OSX 61 | # ========================= 62 | 63 | .DS_Store 64 | .AppleDouble 65 | .LSOverride 66 | 67 | # Thumbnails 68 | ._* 69 | 70 | # Files that might appear on external disk 71 | .Spotlight-V100 72 | .Trashes 73 | 74 | # Directories potentially created on remote AFP share 75 | .AppleDB 76 | .AppleDesktop 77 | Network Trash Folder 78 | Temporary Items 79 | .apdisk 80 | 81 | # Windows 82 | # ========================= 83 | 84 | # Windows image file caches 85 | Thumbs.db 86 | ehthumbs.db 87 | 88 | # Folder config file 89 | Desktop.ini 90 | 91 | # Recycle Bin used on file shares 92 | $RECYCLE.BIN/ 93 | 94 | # Windows Installer files 95 | *.cab 96 | *.msi 97 | *.msm 98 | *.msp 99 | 100 | # Windows shortcuts 101 | *.lnk 102 | config.txt -------------------------------------------------------------------------------- /Door_Control.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import RPi.GPIO as GPIO 3 | import time 4 | import signal 5 | import sys 6 | import httplib, urllib #for Push Notifications 7 | 8 | #config.txt included in .gitignore first line is the token, the second line is the key 9 | config = open('config.txt').readlines() 10 | pushover_token=config[0].rstrip() 11 | pushover_user=config[1] 12 | 13 | 14 | #Setting up Board GPIO Pins 15 | GPIO.setmode(GPIO.BOARD) 16 | GPIO.setup(35,GPIO.OUT) 17 | GPIO.setup(37,GPIO.OUT) 18 | GPIO.setup(33,GPIO.IN)#Locked 19 | GPIO.setup(31,GPIO.IN)#Open 20 | 21 | #Clean kill of script function (Stops Motor, cleans GPIO) 22 | def Safe_Kill(): 23 | print 'Performing safe shutoff!' 24 | GPIO.output(37,False) 25 | GPIO.output(35,False) 26 | GPIO.cleanup() 27 | sys.exit('Motors shutdown, GPIO cleaned') 28 | 29 | def PushOver(message): 30 | conn = httplib.HTTPSConnection("api.pushover.net:443") 31 | conn.request("POST", "/1/messages.json", 32 | urllib.urlencode({ 33 | #I know, I know no keys in source control. Sheesh. 34 | #The old keys no longer work 35 | "token": pushover_token, 36 | "user": pushover_user, 37 | "message": message, 38 | }), { "Content-type": "application/x-www-form-urlencoded" }) 39 | conn.getresponse() 40 | 41 | #Argument controller 42 | if len(sys.argv)>3: #Tests if you've entered too many arguments 43 | print "You've entered too many arguments!" 44 | print "Exiting program..." 45 | sys.exit(0) 46 | 47 | if len(sys.argv)>2: #Argument for door action time 48 | try: 49 | float(sys.argv[2]) 50 | except: 51 | print 'Error: ',str(sys.argv[2]),' is not a number!' 52 | print "Exiting program..." 53 | sys.exit(0) 54 | if int(sys.argv[2])>45: #Checks that a time longer than 45s isn't entered 55 | print 'Please choose a time less than 45s' 56 | print "Exiting program..." 57 | sys.exit(0) 58 | 59 | if len(sys.argv)>1: #Argument for door action 60 | if sys.argv[1]!='close' and sys.argv[1]!='open': 61 | print 'Please choose "open" or "close"' 62 | print "Exiting program..." 63 | sys.exit(0) 64 | 65 | if len(sys.argv)==3: 66 | print 'Forcing door to',str(sys.argv[1]),'for',str(sys.argv[2]),'seconds' 67 | Door_Action=sys.argv[1] 68 | Door_Time=int(sys.argv[2]) 69 | if len(sys.argv)==2: 70 | print 'Forcing door to ',str(sys.argv[1]) 71 | Door_Action=sys.argv[1] 72 | Door_Time=45 #This is a safety time 73 | if len(sys.argv)==1: 74 | Door_Action='default' #Will reverse door state 75 | Door_Time=45 #This is a safety time 76 | 77 | #Start door! 78 | #def DoorControl(): 79 | TimeStart=time.clock() 80 | runTime=0 81 | #Check door status from Magnets 82 | BottomHall=GPIO.input(31) 83 | TopHall=GPIO.input(33) 84 | if BottomHall==0:print 'Door is locked' 85 | if TopHall==0:print 'Door is open' 86 | if BottomHall==1:print 'No magnet sensed on lock' 87 | if TopHall==1:print 'No magnet sensed top' 88 | if Door_Action=='open': #Door is locked 89 | print 'The door is locked!' 90 | print 'The door is going up!' 91 | while TopHall==1 and runTime