Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
UnicycleDumpTruck committed Jul 24, 2013
0 parents commit 42334f7
Show file tree
Hide file tree
Showing 69 changed files with 362 additions and 0 deletions.
Binary file added alarm.mp3
Binary file not shown.
62 changes: 62 additions & 0 deletions alarmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/python

import subprocess
import datetime
import time
import os
import RPi.GPIO as io
import tweepy
import tweetpony

api = tweetpony.API(consumer_key = "ijf5JCxlWLMFdQAAC6PLCQ", consumer_secret = "dAIRyTMNkXjeU09GM9z6OqXvoCnWuOqYWhZA5mrs", access_token = "1480595341-KvFxkXATJXVvuJrqxp7RldWtHAkHUh9KmT7Hnfd", access_token_secret = "1XiknliCvHTwbSe2ZY41n8Cj0Qtejb3SXGzrqQdkV1Q")

io.setmode(io.BCM)

pir_pin = 18
flashingLight_pin = 7

io.setup(pir_pin, io.IN)
io.setup(flashingLight_pin, io.OUT)
io.output(flashingLight_pin, io.LOW)

# --------- Main Program ---------
previous_pir=0

while True:
current_pir=io.input(pir_pin)
if previous_pir==0 and current_pir==1:
with open("/home/pi/Alarm/armed.txt", "r") as fo:
fo.seek(0, 0)
status = fo.read(1)
fo.closed
print "Motion detected, armed status: " + str(status)
if (status == "1"):
subprocess.call("mpg123 /home/pi/Alarm/motiondetect.mp3", shell=True)
time.sleep(10)
with open("/home/pi/Alarm/armed.txt", "r") as fo:
fo.seek(0, 0)
status = fo.read(1)
fo.closed
if (status == "1"):
print "Correct passcode not entered, emailing picture and sounding alarm."
grab_cam = subprocess.Popen("sudo fswebcam -r 640x480 -d /dev/video0 -q /home/pi/Alarm/pictures/%m-%d-%y-%H%M.jpg", shell=True)
grab_cam.wait()
todays_date = datetime.datetime.today()
image_name = todays_date.strftime('%m-%d-%y-%H%M')
image_path = '/home/pi/Alarm/pictures/' + image_name + '.jpg'
subprocess.Popen('echo "Here is your intruder:" | mail -a ' + image_path + ' -s "Intruder Alert" muddysdad@gmail.com', shell=True)

try:
api.update_status_with_media(status = ("Intruder alert: " + todays_date.strftime('%m-%d-%y-%H%M')), media= image_path)
except tweetpony.APIError as err:
print "Oops, something went wrong! Twitter returned error #%i and said: %s" % (err.code, err.description)

io.output(flashingLight_pin, io.HIGH)
subprocess.call("mpg123 /home/pi/Alarm/alarm.mp3", shell=True)
subprocess.call("mpg123 /home/pi/Alarm/surrender.mp3", shell=True)
subprocess.call("mpg123 /home/pi/Alarm/alarm.mp3", shell=True)
io.output(flashingLight_pin, io.LOW)
del_img = subprocess.Popen("sudo rm -rf " + image_path, shell=True)
del_img.wait()
previous_pir=current_pir
time.sleep(1)
104 changes: 104 additions & 0 deletions alarmd.py.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/python

import subprocess
import datetime
import time
import os
import RPi.GPIO as io
#import tweepy
import tweetpony

api = tweetpony.API(consumer_key = "abc", consumer_secret = "def", access_token = "ghi", access_token_secret = "jkl")
user = api.user
print "Hello, @%s!" % user.screen_name
text = raw_input("What would you like to tweet? ")


io.setmode(io.BCM)

pir_pin = 18
flashingLight_pin = 7

io.setup(pir_pin, io.IN)
io.setup(flashingLight_pin, io.OUT)
io.output(flashingLight_pin, io.LOW)

#def setup_api():
# auth = tweepy.OAuthHandler('ijf5JCxlWLMFdQAAC6PLCQ',
# 'dAIRyTMNkXjeU09GM9z6OqXvoCnWuOqYWhZA5mrs')
# auth.set_access_token('1480595341-KvFxkXATJXVvuJrqxp7RldWtHAkHUh9KmT7Hnfd',
# '1XiknliCvHTwbSe2ZY41n8Cj0Qtejb3SXGzrqQdkV1Q')
# return tweepy.API(auth)

def sendPicture():
#print "Taking snapshot"
#import subprocess
grab_cam = subprocess.Popen("sudo fswebcam -r 640x480 -d /dev/video0 -q /home/pi/Alarm/pictures/%m-%d-%y-%H%M.jpg", shell=True)
grab_cam.wait()
#print "Acquiring image file"
#import datetime
todays_date = datetime.datetime.today()
image_name = todays_date.strftime('%m-%d-%y-%H%M')
image_path = '/home/pi/Alarm/pictures/' + image_name + '.jpg'
#print "Sending email"
subprocess.Popen('echo "Here is your intruder:" | mail -a ' + image_path + ' -s "Intruder Alert" muddysdad@gmail.com', shell=True)
#print "Tweeting image"
# status = "Intruder alert: " + todays_date.strftime('%m-%d-%y-%H%M')
api.status_update_with_media(image_path, status = ("Intruder alert: " + todays_date.strftime('%m-%d-%y-%H%M')))
#print "Cleaning up"
del_img = subprocess.Popen("sudo rm -rf " + image_path, shell=True)
del_img.wait()


# --------- Main Program ---------

#fo = open("/home/pi/Alarm/armed.txt", "r")
previous_pir=0

# Authorize Tweepy.
api = setup_api()

while True:
current_pir=io.input(pir_pin)
#print "Previous PIR:" + str(previous_pir) + " Current PIR:" + str(current_pir)
if previous_pir==0 and current_pir==1:
with open("/home/pi/Alarm/armed.txt", "r") as fo:
fo.seek(0, 0)
status = fo.read(1)
fo.closed
print "Motion detected, armed status: " + str(status)
if (status == "1"):
#subprocess.call('echo "Motion detected, please enter your passcode." | festival --tts', shell=True)
subprocess.call("mpg123 /home/pi/Alarm/motiondetect.mp3", shell=True)
#io.output(flashingLight_pin, io.HIGH)#remove
#subprocess.call("mpg123 /home/pi/Alarm/vo/0003.mp3", shell=True)
#io.output(flashingLight_pin, io.LOW)#remove
time.sleep(10)
with open("/home/pi/Alarm/armed.txt", "r") as fo:
fo.seek(0, 0)
status = fo.read(1)
fo.closed
if (status == "1"):
print "Correct passcode not entered, emailing picture and sounding alarm."
grab_cam = subprocess.Popen("sudo fswebcam -r 640x480 -d /dev/video0 -q /home/pi/Alarm/pictures/%m-%d-%y-%H%M.jpg", shell=True)
grab_cam.wait()
todays_date = datetime.datetime.today()
image_name = todays_date.strftime('%m-%d-%y-%H%M')
image_path = '/home/pi/Alarm/pictures/' + image_name + '.jpg'
subprocess.Popen('echo "Here is your intruder:" | mail -a ' + image_path + ' -s "Intruder Alert" muddysdad@gmail.com', shell=True)
# api.status_update_with_media(image_path, status = ("Intruder alert: " + todays_date.strftime('%m-%d-%y-%H%M')))
# del_img = subprocess.Popen("sudo rm -rf " + image_path, shell=True)
# del_img.wait()

#sendPicture()
io.output(flashingLight_pin, io.HIGH)
subprocess.call("mpg123 /home/pi/Alarm/alarm.mp3", shell=True)
#time.sleep(5)
#subprocess.call('echo "Your intrusion has been recorded. Authorities have been notified." | festival --tts', shell=True)
subprocess.call("mpg123 /home/pi/Alarm/surrender.mp3", shell=True)
subprocess.call("mpg123 /home/pi/Alarm/alarm.mp3", shell=True)
io.output(flashingLight_pin, io.LOW)
del_img = subprocess.Popen("sudo rm -rf " + image_path, shell=True)
del_img.wait()
previous_pir=current_pir
time.sleep(1)
Binary file added armed.mp3
Binary file not shown.
1 change: 1 addition & 0 deletions armed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Binary file added disarmed.mp3
Binary file not shown.
195 changes: 195 additions & 0 deletions keypadd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# #####################################################
# Python Library for 3x4 matrix keypad using
# 7 of the avialable GPIO pins on the Raspberry Pi.
#
# This could easily be expanded to handle a 4x4 but I
# don't have one for testing. The KEYPAD constant
# would need to be updated. Also the setting/checking
# of the colVal part would need to be expanded to
# handle the extra column.
#
# Written by Chris Crumpacker
# May 2013
#
# main structure is adapted from Bandono's
# matrixQPI which is wiringPi based.
# https://github.com/bandono/matrixQPi?source=cc
# #####################################################

import RPi.GPIO as GPIO
import time
import subprocess

class keypad():
# CONSTANTS
KEYPAD = [
[1,2,3],
[4,5,6],
[7,8,9],
["*",0,"#"]
]

ROW = [27,23,24,25]
COLUMN = [4,17,22]

def __init__(self):
GPIO.setmode(GPIO.BCM)

def getKey(self):

# Set all columns as output low
for j in range(len(self.COLUMN)):
GPIO.setup(self.COLUMN[j], GPIO.OUT)
GPIO.output(self.COLUMN[j], GPIO.LOW)

# Set all rows as input
for i in range(len(self.ROW)):
GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Scan rows for pushed key/button
# A valid key press should set "rowVal" between 0 and 3.
rowVal = -1
for i in range(len(self.ROW)):
tmpRead = GPIO.input(self.ROW[i])
if tmpRead == 0:
rowVal = i

# if rowVal is not 0 thru 3 then no button was pressed and we can exit
if rowVal < 0 or rowVal > 3:
self.exit()
return

# Convert columns to input
for j in range(len(self.COLUMN)):
GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# Switch the i-th row found from scan to output
GPIO.setup(self.ROW[rowVal], GPIO.OUT)
GPIO.output(self.ROW[rowVal], GPIO.HIGH)

# Scan columns for still-pushed key/button
# A valid key press should set "colVal" between 0 and 2.
colVal = -1
for j in range(len(self.COLUMN)):
tmpRead = GPIO.input(self.COLUMN[j])
if tmpRead == 1:
colVal=j

# if colVal is not 0 thru 2 then no button was pressed and we can exit
if colVal < 0 or colVal > 2:
self.exit()
return

# Return the value of the key pressed
self.exit()
return self.KEYPAD[rowVal][colVal]

def exit(self):
# Reinitialize all rows and columns as input at exit
for i in range(len(self.ROW)):
GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)
for j in range(len(self.COLUMN)):
GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_UP)

if __name__ == '__main__':
# Initialize the keypad class
kp = keypad()
attempt = "0000"
passcode = "3717"
haltcode = "6834"
with open("/home/pi/Alarm/armed.txt", "r+") as fo:
fo.seek(0, 0)
fo.write("0")
fo.closed

GPIO.setmode(GPIO.BCM)
GPIO.setup(10, GPIO.OUT) #Green
GPIO.output(10, GPIO.HIGH)
GPIO.setup(9, GPIO.OUT) #Red
GPIO.output(9, GPIO.LOW)
GPIO.setup(7, GPIO.OUT) #Flashing Light
# GPIO.output(7, GPIO.LOW)

subprocess.call("mpg123 /home/pi/Alarm/ready.mp3", shell=True)

# Loop while waiting for a keypress
while True:
digit = None
while digit == None:
digit = kp.getKey()

# Print the result
print digit
attempt = (attempt[1:] + str(digit))
print attempt

if (attempt == passcode):
with open("/home/pi/Alarm/armed.txt", "r+") as fo:
fo.seek(0, 0)
status = fo.read(1)
print "Correct Passcode, file was:" + status
fo.closed
if (status == "1"):
#system was armed, disarm it
with open("/home/pi/Alarm/armed.txt", "r+") as fo:
fo.seek(0, 0)
fo.write("0")
fo.closed
GPIO.output(10, GPIO.HIGH) #Green LED On
GPIO.output(9, GPIO.LOW) #Red LED off
GPIO.output(7, GPIO.LOW)
subprocess.call("mpg123 /home/pi/Alarm/disarmed.mp3", shell=True)
#subprocess.call('echo "System disarmed." | festival --tts', shell=True)
else:
GPIO.output(10, GPIO.LOW) #Green LED Off
GPIO.output(9, GPIO.HIGH) #Red LED on
# GPIO.output(7, GPIO.HIGH)
subprocess.call("mpg123 /home/pi/Alarm/armed.mp3", shell=True)
time.sleep(10)
with open("/home/pi/Alarm/armed.txt", "r+") as fo:
fo.seek(0, 0)
fo.write("1")
fo.closed
#subprocess.call('echo "System armed." | festival --tts', shell=True)
elif (attempt == haltcode):
subprocess.call("mpg123 /home/pi/Alarm/shutdown.mp3", shell=True)
subprocess.call("halt", shell=True)

# Make video alarm system voiceovers:
elif (attempt == "0001"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0001.mp3", shell=True)
elif (attempt == "0002"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0002.mp3", shell=True)
elif (attempt == "1003"):
time.sleep(10)
GPIO.output(7, GPIO.HIGH)
time.sleep(1)
subprocess.call("mpg123 /home/pi/Alarm/vo/0003.mp3", shell=True)
time.sleep(1)
GPIO.output(7, GPIO.LOW)
elif (attempt == "0004"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0004.mp3", shell=True)
elif (attempt == "0005"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0005.mp3", shell=True)
elif (attempt == "0006"):
time.sleep(3)
GPIO.output(7, GPIO.HIGH)
subprocess.call("mpg123 /home/pi/Alarm/vo/0006.mp3", shell=True)
subprocess.call("mpg123 /home/pi/Alarm/alarm.mp3", shell=True)
subprocess.call("mpg123 /home/pi/Alarm/vo/0006.mp3", shell=True)
GPIO.output(7, GPIO.LOW)
elif (attempt == "0007"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0007.mp3", shell=True)
elif (attempt == "0008"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0008.mp3", shell=True)
elif (attempt == "0009"):
time.sleep(10)
subprocess.call("mpg123 /home/pi/Alarm/vo/0009.mp3", shell=True)

time.sleep(0.5)
Binary file added motiondetect.mp3
Binary file not shown.
Binary file added pictures/.AppleDouble/.Parent
Binary file not shown.
Binary file added pictures/.AppleDouble/06-28-13-1226.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/06-28-13-1245.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/06-28-13-1254.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/06-28-13-1312.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/06-28-13-1322.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/06-28-13-1335.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-12-13-1057.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-140240.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-140446.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-140553.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-141418.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-141438.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-141445.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-141451.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-14:01:15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-150717.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-150925.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-152059.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/.AppleDouble/07-15-13-152118.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/06-28-13-1226.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/06-28-13-1245.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/06-28-13-1254.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/06-28-13-1312.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/06-28-13-1322.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/06-28-13-1335.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pictures/07-12-13-1057.jpg
Binary file added pictures/07-15-13-140240.jpg
Binary file added pictures/07-15-13-140446.jpg
Binary file added pictures/07-15-13-140553.jpg
Binary file added pictures/07-15-13-141418.jpg
Binary file added pictures/07-15-13-141438.jpg
Binary file added pictures/07-15-13-141445.jpg
Binary file added pictures/07-15-13-141451.jpg
Binary file added pictures/07-15-13-14:01:15.jpg
Binary file added pictures/07-15-13-150717.jpg
Binary file added pictures/07-15-13-150925.jpg
Binary file added pictures/07-15-13-152059.jpg
Binary file added pictures/07-15-13-152118.jpg
Binary file added ready.mp3
Binary file not shown.
Binary file added shutdown.mp3
Binary file not shown.
Binary file added surrender.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/.Parent
Binary file not shown.
Binary file added vo/.AppleDouble/0001.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0002.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0003.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0004.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0005.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0006.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0007.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0008.mp3
Binary file not shown.
Binary file added vo/.AppleDouble/0009.mp3
Binary file not shown.
Binary file added vo/0001.mp3
Binary file not shown.
Binary file added vo/0002.mp3
Binary file not shown.
Binary file added vo/0003.mp3
Binary file not shown.
Binary file added vo/0004.mp3
Binary file not shown.
Binary file added vo/0005.mp3
Binary file not shown.
Binary file added vo/0006.mp3
Binary file not shown.
Binary file added vo/0007.mp3
Binary file not shown.
Binary file added vo/0008.mp3
Binary file not shown.
Binary file added vo/0009.mp3
Binary file not shown.

0 comments on commit 42334f7

Please sign in to comment.