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
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ RUN apt-get update && apt-get install -y \
apache2 \
iptables \
nodejs \
python-virtualenv \
python-imaging \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install pip
# RUN easy_install pip

# Install Flask
RUN pip install Flask

# Apache site configuration
ADD chute/000-default.conf /etc/apache2/sites-available/

Expand All @@ -30,6 +37,6 @@ ADD chute/run.sh /usr/local/bin/run.sh
# Set the work dir for nodejs photo server
WORKDIR "/var/www/html"

EXPOSE 80 81 8010
EXPOSE 80 81 8010 8011

CMD ["/bin/bash", "/usr/local/bin/run.sh"]
19 changes: 19 additions & 0 deletions chute/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask
from flask import request
app = Flask(__name__)

@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return ('get message')
else:
return ("error")

@app.route('/')
def hello_world():
return 'Hello, World!'

app.run(host = '0.0.0.0', port = 5001)

#if(__name__ == "__main__"):
# print("In Main")
10 changes: 9 additions & 1 deletion chute/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ mkdir -p /var/www/html/motionLog
chmod a+rw /var/www/html/motionLog

# Execute the file, one pic every 2 seconds
python /usr/local/bin/seccam.py -m_sec 2.0 > seccam.log 2> seccam.err &
python /usr/local/bin/seccam.py -m_sec 5.0 > seccam.log 2> seccam.err &
#python /usr/local/bin/seccam.py -m_sec 2.0 > seccam.log &


#export FLASK_APP = seccam.py
#flask run > flask.log &

# Execute the file, one pic every 2 seconds
# python /usr/local/bin/snapshot.py -m_sec 2.0 > snapshot.log 2> snapshot.err &

# Add the symlink
ln -s --relative /var/www/html/motionLog /var/www/html/app-dist/
Expand Down
82 changes: 78 additions & 4 deletions chute/seccam.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import httplib
import base64
import StringIO
import thread
from flask import Flask
from flask import request

try:
import PIL
Expand All @@ -18,6 +21,63 @@
THRESH_1 = 40.0
THRESH_2 = 60.0

#'''

def create_app(ip, m_save):
app = Flask(__name__)

@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return ('get message')
else:
return ("error")

@app.route('/')
def hello_world():
return 'Hello, World!'

@app.route('/snap')
def takeSnapShot():
print("In snap shot")
jpg = None
fileName = ""
print(ip, m_save)
while(jpg is None):
try:
print("try to get image")
img = getImage(ip)
# Did we get an image?
if(img is None):
print("** SnapShot Failed, retrying")
time.sleep(2.0)
continue
else:
try:
jpg = PIL.Image.open(img)
fileName = "%s%d.jpg" % (m_save, time.time())
print('jpg: %s' % str(fileName))
jpg.save(fileName)
except Exception as e:
time.sleep(2.0)
jpg = None
except KeyboardInterrupt:
break
except Exception as e:
print('!! error: %s' % str(e))
jpg = None
time.sleep(2.0)
return fileName

return app

#'''
def run_app(ip, m_save):
print("\nListen!!!\n")
app = create_app(ip, m_save)
app.run(host = '0.0.0.0', port = 8011)
#'''

def setupArgParse():
p = argparse.ArgumentParser(description='SecCam security suite')
p.add_argument('-calibrate', help='Temporary mode to help calibrate the thresholds', action='store_true')
Expand All @@ -31,9 +91,9 @@ def getImage(ip):
# Here is a portion of the URL
#######################################################################
# TODO1 : Send a HTTP GET Request to the WebCam
# (with Username:'admin' and Password:'').
# We recommend using the httplib package
h = httplib.HTTP(ip, 80)
# (with Username:'admin' and Password:'').
# We recommend using the httplib package
h = httplib.HTTP(ip, 80)
h.putrequest('GET', '/image.jpg')
h.putheader('Host', ip)
h.putheader('User-agent', 'python-httplib')
Expand Down Expand Up @@ -91,6 +151,8 @@ def detectMotion(img1, jpg2):


if(__name__ == "__main__"):
print("In main\n")

p = setupArgParse()
args = p.parse_args()

Expand All @@ -99,6 +161,8 @@ def detectMotion(img1, jpg2):
sens = args.m_sensitivity
m_save = '/var/www/html/motionLog/motion-'

print("After global vars\n")

if(m_sec < 1.0):
print('** For the workshop, please do not use lower than 1.0 for m_sec')
exit()
Expand Down Expand Up @@ -126,6 +190,7 @@ def detectMotion(img1, jpg2):
subnet = ""
ip = ""
while(ip == ""):
print("Try to connect from router to WebCam")
try:

# Get the subnet if haven't yet
Expand Down Expand Up @@ -172,6 +237,15 @@ def detectMotion(img1, jpg2):

print("Found IP %s" % ip)


try:
thread.start_new_thread( run_app, (ip, m_save,) )
except:
print "Error: unable to start thread"

#while(True):
# pass

# Setup while loop requesting images from webcam
while(True):
try:
Expand All @@ -193,7 +267,7 @@ def detectMotion(img1, jpg2):
#######################################################################
# TODO2 : Check the RMS difference and store the image to the proper
# location, for our webserver to read these files they should go
# under the location /srv/www/motionlog/*
# under the location /srv/www/motionlog/*
if(diff > thresh):
print("** Motion! %.3f" % diff)
fileName = "%s%d.jpg" % (m_save, time.time())
Expand Down
Loading