コード例 #1
0
ファイル: startup.py プロジェクト: naziris/HomeSecPi
def pir():
    prevState = 0
    while True:
        status = database().getState()
        while (status == 'True'):
            currState = mcp2.input(sensorPin)
            if prevState == 0 and currState == 128:
                image_name = interact().grabPicture()
                print "Motion detected, armed status: " + status
                os.system(
                    'mpg321 -q /home/pi/HomeSecPi/Speech/motiondetect.mp3 &')
                time.sleep(30)  #Time to enter the passcode 1min
                status = database().getState()

                if (status == 'True'):
                    print "Correct passcode not entered, emailing picture and sounding alarm."
                    #interact().takePicture(image_name)
                    Process(target=interact().takePicture(image_name)).start()
                    os.system(
                        'mpg321 -q /home/pi/HomeSecPi/Speech/alarm.mp3 &')
                    time.sleep(5)
                    os.system(
                        'mpg321 -q /home/pi/HomeSecPi/Speech/surrender.mp3 &')
                    time.sleep(5)
                    os.system(
                        'mpg321 -q /home/pi/HomeSecPi/Speech/alarm.mp3 &')
                    time.sleep(5)
                # else:
                #       if os.path.exists('/home/pi/HomeSecPi/pictures/'+image_name):
                #         os.remove('/home/pi/HomeSecPi/pictures/'+image_name) #Deletes the taken picture in case of False-Alarm
                #         print 'File', image_name, 'has beeen deleted'

            prevState = currState
            time.sleep(1)
コード例 #2
0
ファイル: RControlPanel.py プロジェクト: naziris/HomeSecPi
 def post(self):
     formType = flask.request.form.get('formType')
     digitPass = ""
     if formType == "digitPassword" or "shutdown":
         required = [
             'firstdigit', 'seconddigit', 'thirddigit', 'fourthdigit'
         ]
         for r in required:
             digitPass += flask.request.form.get(r)
         if str(digitPass) == str(database().getFourDigit()):
             state = database().getState()
             if formType == "shutdown":
                 if state == "True":
                     flask.flash("Disarm system before shutting down!")
                     return flask.redirect(flask.url_for('tongles'))
                 else:
                     print "Shutting Down..."
                     database().writeLogs("System has been shutted down")
                     shutdown()
             elif formType == "digitPassword":
                 if state == "True":
                     status().disarm()
                 else:
                     status().arm()
             else:
                 flask.flash(
                     "Something went totally wrong here, please try again!")
                 return flask.redirect(flask.url_for('tongles'))
         else:
             flask.flash("Incorect Password, please try again!")
         return flask.redirect(flask.url_for('tongles'))
コード例 #3
0
ファイル: startup.py プロジェクト: naziris/HomeSecPi
def keypads():
    last_digit = None
    while True:
        list1 = []  #Initialize an empty list
        digit = None
        while len(list1) < 4:  #The length of the passcode will be 4 digits
            while digit == last_digit or digit is None:  #With this loop I prevent multiple press of a number
                digit = keypad().getKey()
                if digit is None:
                    last_digit = None
            list1.append(digit)
            interact().button_Pressed()
            attempt = "".join(map(str, list1))
            lcd.clear()
            lcd.message("Please type your\nPasscode: " + "*" * len(attempt))
            last_digit = digit
        print "Given Passcode:", attempt

        #Verrification of the passcode
        if (attempt == passcode):
            sys_status = (database().getState())
            print "Status:", sys_status
            if (sys_status == "True"):
                #systatusem was armed, disarm it
                status().disarm()
            else:
                status().arm()
        else:
            lcd.clear()
            lcd.message("Wrong Passcode!")
            os.system('mpg321 -q /home/pi/HomeSecPi/Speech/wrongpass.mp3 &')
            database().writeLogs("Wrong passcode has been given on the keypad")
            interact().indication()
            interact().askPass()
    time.sleep(0.5)
コード例 #4
0
ファイル: startup.py プロジェクト: naziris/HomeSecPi
def power():
    prevMode = status().pwr_mode()
    while True:
        currMode = status().pwr_mode()
        if prevMode != currMode:
            if currMode == "External Cable Powering (EPR)":
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/epr.mp3 &')
                lcd.clear()
                lcd.message("External Cable\nPowering (EPR)")
                time.sleep(3)
            elif currMode == "USB Cable Powering":
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/usb.mp3 &')
                lcd.clear()
                lcd.message("USB Cable\nPowering")
                time.sleep(3)
            elif currMode == "Raspberry Pi Powering":
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/pi.mp3 &')
                lcd.clear()
                lcd.message("Raspberry Pi\nPowering")
                time.sleep(3)
            elif currMode == "Battery Powering":
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/battery.mp3 &')
                lcd.clear()
                lcd.message("Battery\nPowering")
                time.sleep(3)
            elif currMode == "Battery Low Powering":
                os.system(
                    'mpg321 -q /home/pi/HomeSecPi/Speech/battery_low.mp3 &')
                lcd.clear()
                lcd.message("Battery Low\nPowering")
                time.sleep(3)
            elif currMode == "CPR Mode":
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/cpr.mp3 &')
                lcd.clear()
                lcd.message("Running on\nCPR Mode")
                time.sleep(3)
            elif currMode == "BPR Mode":
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/bpr.mp3 &')
                lcd.clear()
                lcd.message("Running on\nBPR Mode")
                time.sleep(3)
            else:
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/error.mp3 &')
                lcd.clear()
                lcd.message("Power Reading\nError!")
                time.sleep(3)
            print "Power source has been changed"
            database().writeLogs("Power source has been changed to " +
                                 currMode)
            interact().askPass()
        prevMode = currMode
        time.sleep(1)
コード例 #5
0
ファイル: RControlPanel.py プロジェクト: naziris/HomeSecPi
def getStatus():
    state = database().getState()
    if state == "True":
        status = "Armed"
    else:
        status = "Disarmed"
    return status
コード例 #6
0
ファイル: RControlPanel.py プロジェクト: naziris/HomeSecPi
 def get(self):
     return flask.render_template('logs.html', records=database().getLogs())
コード例 #7
0
ファイル: RControlPanel.py プロジェクト: naziris/HomeSecPi
 def post(self):
     global users
     if 'logout' in flask.request.form:
         flask.session.pop('username', None)
         database().writeLogs("User has been succsessfuly logged out!")
         flask.flash("You've been succsessfuly logged out!")
         return flask.redirect(flask.url_for('login'))
     if 'reset' in flask.request.form:
         Username = flask.request.form.get('username')
         if 'username' not in flask.request.form or (
                 database().getUsername() != Username):  #Check That one
             flask.flash(
                 "Something went totally wrong here. Please to check your username and try again!"
             )
             return flask.redirect(flask.url_for('login'))
         newPassword = database().resetPass()
         emailBody = "You recently asked to reset your password, your new password is: " + newPassword
         interact().sendEmail("Your new Password!", emailBody, "NO",
                              database().getEmail())
         users = database().getUsers()
         flask.flash(
             "Your password has been reset. You'll receive an email shortly with your new password"
         )
         # users = database().getUsers()
         return flask.redirect(flask.url_for('login'))
     required = ['username', 'passwd']
     for r in required:
         if r not in flask.request.form:
             flask.flash("Error: {0} is required.".format(r))
             return flask.redirect(flask.url_for('login'))
     username = flask.request.form['username']
     passwd = flask.request.form['passwd']
     print database().checkHashedPass(passwd, database().getPassword())
     if username in users and (database().checkHashedPass(
             passwd,
             database().getPassword())) == True:
         flask.session['username'] = username
         database().writeLogs("User has been succsessfuly logged in!")
         flask.flash("Login Succsessful!")
         flask.session['userEmail'] = database().getEmail()
         flask.session['mNumber'] = database().getmNumber()
         return flask.redirect(flask.url_for('admin'))
     else:
         flask.flash("Username doesn't exist or incorrect password")
     return flask.redirect(flask.url_for('login'))
コード例 #8
0
ファイル: RControlPanel.py プロジェクト: naziris/HomeSecPi
    def post(self):
        global users
        formType = flask.request.form.get('formType')

        if formType == "changePassword":
            if 'password' not in flask.request.form:
                flask.flash(
                    "Something went totally wrong here. Please try to change your password again!"
                )
                return flask.redirect(flask.url_for('admin'))
            newPassword = database().getHashed(
                flask.request.form.get('password'))
            currentPassword = database().getPassword()
            if newPassword == currentPassword:
                flask.flash(
                    "The password you entered is the same as the current one. Please use a different password and try again!"
                )
                return flask.redirect(flask.url_for('admin'))
            else:
                database().changePass(newPassword)
        elif formType == "editUsername":
            if 'username' not in flask.request.form:
                flask.flash(
                    "Something went totally wrong here. Please try to change your password again!"
                )
                return flask.redirect(flask.url_for('admin'))
            newUsername = flask.request.form.get('username')
            currentUsername = database().getUsername()
            if newUsername == currentUsername:
                flask.flash(
                    "The username you entered is the same as the current one. Please use a different username and try again!"
                )
                return flask.redirect(flask.url_for('admin'))
            else:
                database().changeUsername(newUsername)
        elif formType == "editemail":
            if 'email' not in flask.request.form:
                flask.flash(
                    "Something went totally wrong here. Please try to change your e-Mail address again!"
                )
                return flask.redirect(flask.url_for('admin'))
            newemail = flask.request.form.get('email')
            currentemail = database().getEmail()
            if newemail == currentemail:
                flask.flash(
                    "The e-Mail address you entered is the same as the current one. Please use a different one and try again!"
                )
                return flask.redirect(flask.url_for('admin'))
            else:
                database().changeEmail(newemail)
        elif formType == "editphoneNumber":
            if 'phoneNumber' not in flask.request.form:
                flask.flash(
                    "Something went totally wrong here. Please try to change your phone number again!"
                )
                return flask.redirect(flask.url_for('admin'))
            getPhonenumber = flask.request.form.get('phoneNumber')
            country = flask.request.form.get('countrySelectBox')
            if country == 'GB':
                newPhonenumber = '44{}'.format(
                    getPhonenumber[1:] if getPhonenumber.
                    startswith('0') else getPhonenumber)
            elif country == 'US':
                newPhonenumber = '1{}'.format(getPhonenumber)
            currentPhonenumber = database().getmNumber()
            if newPhonenumber == currentPhonenumber:
                flask.flash(
                    "The phone number you entered is the same as the current one. Please use a different one and try again!"
                )
                return flask.redirect(flask.url_for('admin'))
            database().changePhoneNumber(newPhonenumber)
        elif formType == "editDigitPassword":
            if 'currentPassword' not in flask.request.form:
                flask.flash(
                    "Something went totally wrong here. Please try to change your four-digit password again!"
                )
                return flask.redirect(flask.url_for('admin'))
            newPassword = flask.request.form.get('newPassword')
            currentPassword = database().getFourDigit()
            if currentPassword != flask.request.form.get('currentPassword'):
                flask.flash(
                    "incorrect current four-digit password, please try again")
                return flask.redirect(flask.url_for('admin'))
            elif newPassword == currentPassword:
                flask.flash(
                    "The password you entered is the same as the current one. Please use a different password and try again!"
                )
                return flask.redirect(flask.url_for('admin'))
            else:
                database().changeFdigit(newPassword)
        else:
            flask.flash(
                "Something went totally wrong here. Please try to change the preffered details again"
            )
            return flask.render_template('admin.html')
        flask.flash(
            "Your settings have been  modified succsessfuly. In order your changes to be effectful, you will be logged out in a few seconds!"
        )
        users = database().getUsers()
        flask.session.pop('username', None)
        sleep(1)
        flask.flash("You've been succsessfuly logged out!")
        return flask.redirect(flask.url_for('index'))
コード例 #9
0
ファイル: RControlPanel.py プロジェクト: naziris/HomeSecPi
import flask, flask.views
from flask import jsonify, request, Response
from werkzeug.contrib.fixers import ProxyFix
from camera_pi import Camera
import functools
from subprocess import check_output
import os
from functions import status, interact, database
import urllib
import re
from time import sleep

app = flask.Flask(__name__)
app.secret_key = 'YourSecurityKey'
users = database().getUsers()


class Main(flask.views.MethodView):
    def get(self):
        return flask.render_template('welcome.html')


def login_required(method):
    @functools.wraps(method)
    def wrapper(*args, **kwargs):
        if 'username' in flask.session:
            return method(*args, **kwargs)
        else:
            flask.flash("A login is required to see the page!")
            return flask.redirect(flask.url_for('login'))
コード例 #10
0
ファイル: startup.py プロジェクト: naziris/HomeSecPi
                os.system('mpg321 -q /home/pi/HomeSecPi/Speech/error.mp3 &')
                lcd.clear()
                lcd.message("Power Reading\nError!")
                time.sleep(3)
            print "Power source has been changed"
            database().writeLogs("Power source has been changed to " +
                                 currMode)
            interact().askPass()
        prevMode = currMode
        time.sleep(1)


try:
    #Initialize the hardware system
    attempt = ""
    passcode = database().getFourDigit()
    database().switchOff()
    interact().initialize_Output()
    mcp2.output(buzzer, 1)
    time.sleep(0.3)
    mcp2.output(buzzer, 0)
    mcp2.output(led_green, 1)  # Set Green LED as High
    lcd.clear()
    ip = interact().GetInIP()
    lcd.message("IP:\n" + ip)
    time.sleep(5)
    lcd.clear()
    lcd.message("System Ready!")
    print "System Ready audio file playing!"
    os.system('mpg321 -q /home/pi/HomeSecPi/Speech/ready.mp3 &')
    time.sleep(3)