Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
log.txt
SECRET
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.9"
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

I have used code from this fork but added code on top of it with authentication and a garage stream

- Added only one sensor for open not close(This was a personal thing, I didnt have long enough wire to add another sensor).
- Adding a camera using IPWebCam and an old phone
- Changed UI to reflect some new changes including a garage live stream and a trigger button
- Added flask login

_________________________________________________________________________
YouTube Video Instructions found here: https://youtu.be/Fcx6wANw9KM

Setting up a Flask web server to control your garage door & display the door status & log usage.
Expand Down
Empty file added __init__.py
Empty file.
17 changes: 17 additions & 0 deletions camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# this is just an example for how to use an IP camera

import cv2
import time
import numpy as np

capture = cv2.VideoCapture('http://192.168.68.118:4747/video')

while(True):
ret, frame = capture.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
time.sleep(5)

capture.release()
cv2.destroyAllWindows()
18 changes: 18 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class User():
def __init__(self, id, username, active=True):
self.id = id
self.username = username
self.active = active

def is_active(self):
return True

def is_authenticated(self):
return True

def get_id(self):
return self.id

USERS = {
"1221" : User("1221", 'user1')
}
60 changes: 60 additions & 0 deletions garageFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import RPi.GPIO as GPIO
import time
from werkzeug.security import generate_password_hash, check_password_hash
import cv2
import numpy as np

import RPi.GPIO as GPIO
# the pin numbers refer to the board connector not the chip
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
# set up pin ?? (one of the above listed pins) as an input with a pull-up resistor
GPIO.setup(18, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(7, GPIO.OUT)
GPIO.output(7, GPIO.HIGH)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, GPIO.HIGH)


PASSWORD_HASH = 'CHANGE TO A SHA256 HASH'

# Example to generate password Hash - Example below is not the actual Password
# print(generate_password_hash('test','sha256'))



def checkGaragePassword(input_password):
return check_password_hash(PASSWORD_HASH,input_password)


def triggerGarage():
GPIO.output(7, GPIO.LOW)
time.sleep(1)
GPIO.output(7, GPIO.HIGH)
print("Garage Triggered")
time.sleep(12)


def checkGarageStatus():
if GPIO.input(18) == GPIO.LOW:
print("Garage is Open")
return 'Open'
else:
print("Garage is Closed or Opening/Closing")
return 'Question'


def garageCamera():
camera = cv2.VideoCapture('http://192.168.68.118:4747/video')

while True:
success, frame = camera.read() # read the camera frame

if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
time.sleep(4)
88 changes: 46 additions & 42 deletions log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from datetime import datetime


logfile = open("/home/pi/GarageWeb/static/log.txt","a")
logfile.write(datetime.now().strftime(" Program Starting -- %Y/%m/%d -- %H:%M -- Hello! \n"))
logfile = open("/home/piwhite/Documents/github/GarageControl/static/log.txt", "a")
logfile.write(datetime.now().strftime(
" Program Starting -- %Y/%m/%d -- %H:%M -- Hello! \n"))
logfile.close()
print(datetime.now().strftime(" Program Starting -- %Y/%m/%d -- %H:%M -- Hello! \n"))
print(datetime.now().strftime(
" Program Starting -- %Y/%m/%d -- %H:%M -- Hello! \n"))

print " Control + C to exit Program"
print("Control + C to exit Program")

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
Expand All @@ -18,48 +20,50 @@
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
time.sleep(1)

TimeDoorOpened = datetime.strptime(datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S') #Default Time
DoorOpenTimer = 0 #Default start status turns timer off
DoorOpenTimerMessageSent = 1 #Turn off messages until timer is started
TimeDoorOpened = datetime.strptime(datetime.strftime(
datetime.now(), '%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') # Default Time
DoorOpenTimer = 0 # Default start status turns timer off
DoorOpenTimerMessageSent = 1 # Turn off messages until timer is started

try:
while 1 >= 0:
time.sleep(1)
if DoorOpenTimer == 1: #Door Open Timer has Started
currentTimeDate = datetime.strptime(datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
if (currentTimeDate - TimeDoorOpened).seconds > 900 and DoorOpenTimerMessageSent == 0:
print "Your Garage Door has been Open for 15 minutes"
DoorOpenTimerMessageSent = 1
while 1 >= 0:
time.sleep(1)
if DoorOpenTimer == 1: # Door Open Timer has Started
currentTimeDate = datetime.strptime(datetime.strftime(
datetime.now(), '%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')
if (currentTimeDate - TimeDoorOpened).seconds > 900 and DoorOpenTimerMessageSent == 0:
print("Your Garage Door has been Open for 15 minutes")
DoorOpenTimerMessageSent = 1

if GPIO.input(16) == GPIO.HIGH and GPIO.input(18) == GPIO.HIGH: #Door Status is Unknown
logfile = open("/home/pi/GarageWeb/static/log.txt","a")
logfile.write(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Opening/Closing \n"))
logfile.close()
print(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Opening/Closing \n"))
while GPIO.input(16) == GPIO.HIGH and GPIO.input(18) == GPIO.HIGH:
time.sleep(.5)
else:
if GPIO.input(16) == GPIO.LOW: #Door is Closed
logfile = open("/home/pi/GarageWeb/static/log.txt","a")
logfile.write(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Closed \n"))
logfile.close()
print(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Closed"))
DoorOpenTimer = 0
if GPIO.input(16) == GPIO.HIGH and GPIO.input(18) == GPIO.HIGH: #Door Status is Unknown
logfile = open("/home/piwhite/Documents/github/GarageControl/static/log.txt","a")
logfile.write(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Opening/Closing \n"))
logfile.close()
print(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Opening/Closing \n"))
while GPIO.input(16) == GPIO.HIGH and GPIO.input(18) == GPIO.HIGH:
time.sleep(.5)
else:
if GPIO.input(16) == GPIO.LOW: #Door is Closed
logfile = open("/home/piwhite/Documents/github/GarageControl/static/log.txt","a")
logfile.write(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Closed \n"))
logfile.close()
print(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Closed"))
DoorOpenTimer = 0

if GPIO.input(18) == GPIO.LOW: #Door is Open
logfile = open("/home/pi/GarageWeb/static/log.txt","a")
logfile.write(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Open \n"))
logfile.close()
print(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Open"))
#Start Door Open Timer
TimeDoorOpened = datetime.strptime(datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
DoorOpenTimer = 1
DoorOpenTimerMessageSent = 0
if GPIO.input(18) == GPIO.LOW: #Door is Open
logfile = open("/home/piwhite/Documents/github/GarageControl/static/log.txt","a")
logfile.write(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Open \n"))
logfile.close()
print(datetime.now().strftime("%Y/%m/%d -- %H:%M:%S -- Door Open"))
#Start Door Open Timer
TimeDoorOpened = datetime.strptime(datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S'),'%Y-%m-%d %H:%M:%S')
DoorOpenTimer = 1
DoorOpenTimerMessageSent = 0


except KeyboardInterrupt:
logfile = open("/home/pi/GarageWeb/static/log.txt","a")
logfile.write(datetime.now().strftime(" Log Program Shutdown -- %Y/%m/%d -- %H:%M -- Goodbye! \n"))
logfile.close()
print(datetime.now().strftime(" Log Program Shutdown -- %Y/%m/%d -- %H:%M -- Goodbye! \n"))
GPIO.cleanup()
logfile = open("/home/piwhite/Documents/github/GarageControl/static/log.txt","a")
logfile.write(datetime.now().strftime(" Log Program Shutdown -- %Y/%m/%d -- %H:%M -- Goodbye! \n"))
logfile.close()
print(datetime.now().strftime(" Log Program Shutdown -- %Y/%m/%d -- %H:%M -- Goodbye! \n"))
GPIO.cleanup()
23 changes: 4 additions & 19 deletions relaytest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
print " Control + C to exit Program"
print(" Control + C to exit Program")

import time

Expand All @@ -9,26 +9,11 @@
GPIO.output(7, GPIO.HIGH) # sets the pin output to high
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, GPIO.HIGH)
GPIO.setup(13, GPIO.OUT)
GPIO.output(13, GPIO.HIGH)
GPIO.setup(15, GPIO.OUT)
GPIO.output(15, GPIO.HIGH)

try:
while 1 >=0:
GPIO.output(7, GPIO.LOW) # turns the first relay switch ON
time.sleep(.5) # pauses system for 1/2 second
GPIO.output(7, GPIO.HIGH) # turns the first relay switch OFF
GPIO.output(11, GPIO.LOW) # turns the second relay switch ON
time.sleep(.5)
GPIO.output(11, GPIO.HIGH)
GPIO.output(13, GPIO.LOW)
time.sleep(.5)
GPIO.output(13, GPIO.HIGH)
GPIO.output(15, GPIO.LOW)
time.sleep(.5)
GPIO.output(15, GPIO.HIGH)
time.sleep(.5)
GPIO.output(7, GPIO.LOW) # turns the first relay switch ON
time.sleep(.5) # pauses system for 1/2 second
GPIO.output(7, GPIO.HIGH) # turns the first relay switch OFF

except KeyboardInterrupt: # Stops program when "Control + C" is entered
GPIO.cleanup() # Turns OFF all relay switches
23 changes: 23 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
bcrypt==4.0.1
click==8.1.3
dnspython==2.3.0
email-validator==2.0.0.post1
Flask==2.2.3
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.0.3
Flask-WTF==1.1.1
idna==3.4
importlib-metadata==6.5.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
numpy==1.24.2
opencv-python==4.5.3.56
pygame==2.3.0
RPi.GPIO==0.7.1
SQLAlchemy==2.0.9
typing_extensions==4.5.0
Werkzeug==2.2.3
WTForms==3.0.1
zipp==3.15.0
3 changes: 0 additions & 3 deletions static/Closed.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<body bgcolor="green">
<center>
<br>
<form action="/Garage" method="post" id="garageform">
<input id="garagecode" name="garagecode" type="text "pattern="[0-9]*" value="" STYLE="background-color:white;">
</form>
<img src="/images/GarageGreen.gif" width="90%" onclick="document.forms['garageform'].submit();">
<br><br><a href="/Log">Click for Log File</a><br><br>
</center>
Expand Down
3 changes: 0 additions & 3 deletions static/Open.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<body bgcolor="red">
<center>
<br>
<form action="/Garage" method="post" id="garageform">
<input id="garagecode" name="garagecode" type="text "pattern="[0-9]*" value="" STYLE="background-color:white;">
</form>
<img src="/images/GarageRed.gif" width="90%" onclick="document.forms['garageform'].submit();">
<br><br><a href="/Log">Click for Log File</a><br><br>
</center>
Expand Down
7 changes: 2 additions & 5 deletions static/Question.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
<link rel="stylesheet" type="text/css" href="stylesheet.css">

</head>
<body bgcolor="orange">
<body>
<center>
<br>
<form action="/Garage" method="post" id="garageform">
<input id="garagecode" name="garagecode" type="text "pattern="[0-9]*" value="" STYLE="background-color:white;">
</form>
<img src="/images/GarageQuestion.gif" width="90%" onclick="document.forms['garageform'].submit();">
<img src="/static/images/GarageQuestion.gif" width="90%">
<br><br><a href="/Log">Click for Log File</a><br><br>
</center>
</body></html>
Loading