def create_alert(): if request.method == 'POST': camera = request.form.get('camera') event = request.form.get('eventdetail') alarmstate = request.form.get('alarmstate') person = request.form.get('person') push_alert = request.form.get('push_alert') email_alert = request.form.get('email_alert') trigger_alarm = request.form.get('trigger_alarm') notify_police = request.form.get('notify_police') actions = { 'push_alert': push_alert, 'email_alert': email_alert, 'trigger_alarm': trigger_alarm, 'notify_police': notify_police } with Home_Surveillance.alerts_lock: Home_Surveillance.alerts.append( SurveillanceSystem.Alert( alarmstate, camera, event, person, actions)) #alarmState,camera, event, person, action) Home_Surveillance.alerts[-1].id data = { "alert_id": Home_Surveillance.alerts[-1].id, "alert_message": "Alert if " + Home_Surveillance.alerts[-1].alertString } return jsonify(data) return render_template('index.html')
def create_alert(): if request.method == 'POST': camera = request.form.get('camera') emailAddress = request.form.get('emailAddress') event = request.form.get('eventdetail') alarmstate = request.form.get('alarmstate') person = request.form.get('person') push_alert = request.form.get('push_alert') email_alert = request.form.get('email_alert') trigger_alarm = request.form.get('trigger_alarm') notify_police = request.form.get('notify_police') confidence = request.form.get('confidence') #print "unknownconfidence: " + confidence app.logger.info("unknownconfidence: " + confidence) actions = { 'push_alert': push_alert, 'email_alert': email_alert, 'trigger_alarm': trigger_alarm, 'notify_police': notify_police } with HomeSurveillance.alertsLock: HomeSurveillance.alerts.append( SurveillanceSystem.Alert(alarmstate, camera, event, person, actions, emailAddress, int(confidence))) HomeSurveillance.alerts[-1].id data = { "alert_id": HomeSurveillance.alerts[-1].id, "alert_message": "Alert if " + HomeSurveillance.alerts[-1].alertString } return jsonify(data) return render_template('index.html')
def create_alert(): if request.method == 'POST': print("in create alert") data = request.get_json() # pdb.set_trace() camera = data['camera'] emailAddress = data['emailAddress'] event = data['eventdetail'] alarmstate = data['alarmstate'] person = data['person'] push_alert = data['push_alert'] email_alert = data['email_alert'] trigger_alarm = data['trigger_alarm'] notify_police = data['notify_police'] confidence = data['confidence'] print("in create alert, info received from request form") # pdb.set_trace() #print "unknownconfidence: " + confidence app.logger.info("unknownconfidence: " + confidence) print("unknownconfidence: " + confidence) actions = { 'push_alert': push_alert, 'email_alert': email_alert, 'trigger_alarm': trigger_alarm, 'notify_police': notify_police } jsonify(actions) print("in create alert, before 'with HomeSurveillance.alertsLock'") with HomeSurveillance.alertsLock: print("in create alert, calling alerts.append") HomeSurveillance.alerts.append( SurveillanceSystem.Alert(alarmstate, camera, event, person, actions, emailAddress, int(confidence))) print("in create alert, after HomeSurveillance.alertsLock") HomeSurveillance.alerts[-1].id data = { "alert_id": HomeSurveillance.alerts[-1].id, "alert_message": "Alert if " + HomeSurveillance.alerts[-1].alertString } print("end of create alert") return jsonify(data) return render_template('index_wcam.html')
#import redis from flask import Flask, render_template, Response, redirect, url_for, request, jsonify, send_file import Camera from flask.ext.socketio import SocketIO, send, emit #Socketio depends on gevent import SurveillanceSystem import json import logging import threading import time from random import random app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app) Home_Surveillance = SurveillanceSystem.Surveillance_System() thread1 = threading.Thread() thread2 = threading.Thread() thread1.daemon = False thread2.daemon = False @app.route('/', methods=['GET', 'POST']) def login(): error = None if request.method == 'POST': if request.form['username'] != 'admin' or request.form[ 'password'] != 'admin': error = 'Invalid username or password. Please try again' else:
import SurveillanceSystem import json import logging from logging.handlers import RotatingFileHandler import threading import time from random import random import os import sys import cv2 import psutil LOG_FILE = 'logs/WebApp.log' # Initialises system variables, this object is the heart of the application HomeSurveillance = SurveillanceSystem.SurveillanceSystem() # Threads used to continuously push data to the client alarmStateThread = threading.Thread() facesUpdateThread = threading.Thread() monitoringThread = threading.Thread() alarmStateThread.daemon = False facesUpdateThread.daemon = False monitoringThread.daemon = False # Flask setup app = Flask('SurveillanceWebServer') app.config['SECRET_KEY'] = os.urandom(24) # Used for session management socketio = SocketIO(app) photos = UploadSet('photos', IMAGES) app.config['UPLOADED_PHOTOS_DEST'] = 'uploads/imgs' configure_uploads(app, photos)
def connect(): # Need visibility of global thread object global alarmStateThread global facesUpdateThread global monitoringThread #print "\n\nclient connected\n\n" app.logger.info("client connected") if not facesUpdateThread.isAlive(): #print "Starting facesUpdateThread" app.logger.info("Starting facesUpdateThread") facesUpdateThread = threading.Thread(name='websocket_process_thread_', target=update_faces, args=()) facesUpdateThread.start() if not monitoringThread.isAlive(): #print "Starting monitoringThread" app.logger.info("Starting monitoringThread") monitoringThread = threading.Thread(name='monitoring_process_thread_', target=system_monitoring, args=()) monitoringThread.start() cameraData = {} cameras = [] allCameras = DataBase.cam_master('get')('NULL') db_url_list = [val[1] for val in allCameras.items()] url_list = [c.url for c in HomeSurveillance.cameras] #print("DB: {}".format(db_url_list)) #print("System: {}".format(url_list)) #print(cameraData) with HomeSurveillance.camerasLock: for key, value in allCameras.items(): cameraData = {'camNum': key, 'url': value} app.logger.info(cameraData) cameras.append(cameraData) if not value in url_list: HomeSurveillance.add_camera( SurveillanceSystem.Camera.IPCamera(value)) else: print('cam already present') #print(cameraData) systemData = { 'camNum': len(HomeSurveillance.cameras), 'people': HomeSurveillance.peopleDB, 'cameras': cameras, 'onConnect': True } #Create default alert with HomeSurveillance.alertsLock: HomeSurveillance.alerts.append( SurveillanceSystem.Alert(DataBase, socketio, '', 'all', 'Recognition', 'unknown', '', '', 0, 1)) socketio.emit('system_data', json.dumps(systemData), namespace='/surveillance')