Esempio n. 1
0
def main():
    front_mode = 1
    three_mode = 3
    num_mode = 0

    while True:
        if num_mode == 11:
            print "Front Mode"
            num_mode = c_mode(front_mode)
        elif num_mode == 22:
            print "Three Mode"
            num_mode = c_mode(three_mode)
        elif num_mode == 33:
            print "Changing to Distance Mode"
            break
            num_mode = d_mode(three_mode)
        elif num_mode == 10:
            print "Rebooting"
            break
        elif num_mode == 30:
            print "Sending Message"
            call('./runScript.sh')
            num_mode = send_msg_temp
            if send_msg_temp2 == 1:
                respMessage("ECamera")
                startThread()
        elif num_mode == 0:
            print "Default Front Mode"
            time.sleep(2)
            num_mode = c_mode(front_mode)
Esempio n. 2
0
def capture(c_num):
    try:
        respMessage("CapLoct")
        for x in range(c_num):
            camera.resolution = (1024, 768)
            camera.start_preview()
            time.sleep(3)
            camera.capture('ePhotos/Capture' + str(x) + '.jpg')
            camera.stop_preview()
            dirImg.append('ePhotos/Capture' + str(x) + '.jpg')
            print "Capture" + str(x)
        resp = 'success'
    except:
        resp = 'failure'
        print "Error capturing"
    return resp
def sendSMS(uname, hashCode, numbers, sender, message):
    try:
        respMessage("SendingSMS")
        data = urllib.parse.urlencode({
            'username': uname,
            'hash': hashCode,
            'numbers': numbers,
            'message': message,
            'sender': sender
        })
        data = data.encode('utf-8')
        request = urllib.request.Request("http://api.txtlocal.com/send/?")
        f = urllib.request.urlopen(request, data)
        fr = f.read().decode('utf-8')
        msg = json.loads(fr)
        response = msg['status']
        return response
    except:
        error = "Error"
        return error
Esempio n. 4
0
def send_mail(u_name, u_pass):
    try:
        respMessage("SendingMail")
        for file in dirImg:
            fp = open(file, 'rb')
            img = MIMEImage(fp.read())
            fp.close()
            msg.attach(img)

        s = smtplib.SMTP('smtp.gmail.com', 587)
        s.starttls()
        s.login(user=u_name, password=u_pass)
        s.sendmail(me, toaddr, msg.as_string())
        s.quit()

        resp = 'success'
        print "Message Sent!"
    except:
        resp = 'failure'
        print("Error: unable to send email")

    return resp
Esempio n. 5
0
def call_mode(m_num, bpin, btn):
    btn_num = 0
    count = 0
    global LOOP

    if btn == "Panic":
        respMessage("Assist")
    elif btn == "Shutdown":
        respMessage("Reboot")
    elif btn == "Mode" and m_num == 1:
        respMessage(3)
    elif btn == "Mode" and m_num == 3:
        respMessage(1)
    elif btn == "PiCam" and LOOP == False:
        respMessage("ECamera")
    elif btn == "PiCam" and LOOP == True:
        respMessage("DCamera")

    while GPIO.input(bpin) == 0:
        print "Button: ", btn
        count += 1
        time.sleep(1)

        if count == 3:
            respMessage("Beep")
            print "Success"
            if btn == "Shutdown":
                print "Rebooting"
                LOOP = False
                print LOOP
                btn_num = 10
                time.sleep(2)
                break
            elif btn == "Mode":
                if m_num == 3:
                    print "Changing to Front Mode..."
                    btn_num = 11
                    time.sleep(2)
                    break
                elif m_num == 1:
                    print "Changing to Three Mode..."
                    btn_num = 22
                    time.sleep(2)
                    break
                break
            elif btn == "Panic":
                global send_msg_temp2
                print LOOP
                if LOOP == True:
                    send_msg_temp2 = 1
                    #respMessage("DCamera")
                    LOOP = False
                    print LOOP
                print "Sending Message"
                btn_num = 30
                time.sleep(5)
                break
            elif btn == "PiCam":
                if LOOP == False:
                    startThread()
                elif LOOP == True:
                    print "Disabling Camera"
                    #respMessage("DCamera")
                    LOOP = False
                    print LOOP
                    time.sleep(2)
                btn_num = m_num

        if count < 3 and GPIO.input(bpin) == 1:
            respMessage("Cancel")
            print "Cancelling"
            time.sleep(2)
            btn_num = m_num
    return btn_num
Esempio n. 6
0
        s.sendmail(me, toaddr, msg.as_string())
        s.quit()

        resp = 'success'
        print "Message Sent!"
    except:
        resp = 'failure'
        print("Error: unable to send email")

    return resp


num = 2
captured = capture(num)

if captured == 'success':
    respMessage("LoctCaptured")
    print 'Images captured'
    s_mail = send_mail(uname, upass)

    if s_mail == 'success':
        respMessage("ESent")
        print 'Mail sent successfully'
    elif s_mail == 'failure':
        respMessage("Error")
        print 'Unable to send mail'
elif captured == 'failure':
    respMessage("Error")
    print 'Unable to capture images'
dirImg = []  #reinitialize
def call_mode(m_num, bpin, btn):
    btn_num = 0
    count = 0
    global LOOP

    if btn == "Panic":
        respMessage("Assist")
    elif btn == "Shutdown":
        respMessage("Reboot")
    elif btn == "Mode" and m_num == 1:
        respMessage(3)
    elif btn == "Mode" and m_num == 3:
        respMessage(1)

    while GPIO.input(bpin) == 0:
        print "Button: ", btn
        count += 1
        time.sleep(1)

        if count == 3:
            respMessage("Beep")
            print "Success"
            if btn == "Shutdown":
                print "Rebooting"
                btn_num = 10
                time.sleep(2)
                break
            elif btn == "Mode":
                if m_num == 3:
                    print "Changing to Front Mode..."
                    btn_num = 11
                    time.sleep(2)
                    break
                elif m_num == 1:
                    print "Changing to Three Mode..."
                    btn_num = 22
                    time.sleep(2)
                    break
                break
            elif btn == "Panic":
                print "Sending Message"
                btn_num = 30
                time.sleep(2)
                break
            elif btn == "PiCam":
                if LOOP == False:
                    print "Starting Camera"
                    LOOP = True
                    print LOOP
                    time.sleep(2)
                    threading.Thread(target=camThread, args=()).start()
                    time.sleep(2)
                    #camT.start()
                elif LOOP == True:
                    print "Disabling Camera"
                    LOOP = False
                    print LOOP
                    time.sleep(2)
                    #threading.Thread(target=camThread, args=()).join()
                    #video.release()
                    #cv2.destroyAllWindows()
                btn_num = m_num

        if count < 3 and GPIO.input(bpin) == 1:
            respMessage("Cancel")
            print "Cancelling"
            time.sleep(2)
            btn_num = m_num
    return btn_num
def sendSMS(uname, hashCode, numbers, sender, message):
    try:
        respMessage("SendingSMS")
        data = urllib.parse.urlencode({
            'username': uname,
            'hash': hashCode,
            'numbers': numbers,
            'message': message,
            'sender': sender
        })
        data = data.encode('utf-8')
        request = urllib.request.Request("http://api.txtlocal.com/send/?")
        f = urllib.request.urlopen(request, data)
        fr = f.read().decode('utf-8')
        msg = json.loads(fr)
        response = msg['status']
        return response
    except:
        error = "Error"
        return error


resp = sendSMS(username, hash, receiver, sender, message)
print(resp)
if resp == 'failure' or resp == 'Error':
    respMessage("Error")
    print('Error: Unable to send text message')
elif resp == 'success':
    respMessage("MSent")
    print('Success: Text Message sent successfully')