Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera Support and More #2

Merged
merged 3 commits into from
May 8, 2018
Merged
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
105 changes: 2 additions & 103 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,3 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# vscode
.vscode/
src/__pycache__/
src/credentials.ini
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# vigilo
This repo contains my efforts to make a smart security system
# Vigilo
This repo contains our efforts to make a smart security system.

### Prerequisites

#### Hardware
The following hardware was used to for the Vigilo Security System:
* Raspberry Pi 3 B+ Starter Kit [Amazon](https://www.amazon.com/gp/product/B07BCC8PK7/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1)
* Adafruit Magnetic Sensor [Amazon](https://www.amazon.com/gp/product/B01GQFUYAS/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1)
* Logitech C270 Webcam [Amazon](https://www.amazon.com/Logitech-Widescreen-Recording-Certified-Refurbished/dp/B071KT6W9P/ref=sr_1_1?ie=UTF8&qid=1525758605&sr=8-1&keywords=logitech+c270&dpID=41HVqwN850L&preST=_SX300_QL70_&dpSrc=srch)
* USB Hub with External Power [Amazon](https://www.amazon.com/Adesso-AUH-2070P-Port-Power-Adapter/dp/B07BK5539K/ref=sr_1_5?s=electronics&ie=UTF8&qid=1525758650&sr=1-5&keywords=adesso+usb+hub)
* Jumper Wires [Amazon](https://www.amazon.com/120pcs-Multicolored-Breadboard-Arduino-raspberry/dp/B01LZF1ZSZ/ref=sr_1_fkmr0_1?s=electronics&ie=UTF8&qid=1525758697&sr=1-1-fkmr0&keywords=heirtronic+jumper+wires)

#### Dependencies
To install dependencies run the following commands on your RasberryPi (running Raspbian):
* ARP Scan:
`sudo apt-get install arp-scan -y`
* FS Webcam:
`sudo apt-get install fswebcam -y`
* Python Libraries:
* To install of the pythond dependencies run from the root directory:
`pip3 install -r requirements.txt`

Alternatively, you can run `pip3 install imgurpython` and `pip3 install twilio.rest`

#### Configuration Variables
Create a file at `./src/credentials.ini` and populate with relevant credentials:
```
[Imgur]
USERNAME = *****
PASSWORD = *****
CLIENT_ID = *****
CLIENT_SECRET = *****
ACCESS_TOKEN = *****
REFRESH_TOKEN = *****
[Twilio]
SID = *****
TOKEN = *****
TO = *****
FROM = *****
[User]
NAME = *****
MAC = *****
PICTURE *****
```
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
imgurpython

twilio.rest

34 changes: 0 additions & 34 deletions src/imgurUploader.py

This file was deleted.

100 changes: 73 additions & 27 deletions src/vigilo.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
import time
import configparser
import os
import subprocess
import time

import RPi.GPIO as GPIO
from imgurpython import ImgurClient
from twilio.rest import Client

# Getting configuration variables
configurations = configparser.ConfigParser()
configurations.read('credentials.ini')

# Pi and pin setup
GPIO.setmode(GPIO.BCM)
DOOR_SENSOR_PIN = 18
GPIO.setup(DOOR_SENSOR_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)

# We keep track of when the last scan was done
last_scan = None
# The individual who's device must be on the network
individual = "NAME"
# The device's MAC address
address = "xx:xx:xx:xx:xx:xx"
# The current state of the network
network = None
# User setup
last_scan = None # We keep track of when the last scan was done
network = None # The current state of the network
individual = configurations.get("User", "NAME") # The individual who's device must be on the network
address = configurations.get("User", "MAC") # The device's MAC address
picture_path = configurations.get("User", "PICTURE") # The location of stored picture ¨./intruder.jpg¨ recomended
# print(individual, address, picture_path)

# Twilio setup
twilio_account = configurations.get("Twilio", "SID")
twilio_token = configurations.get("Twilio", "TOKEN")
txt_to = configurations.get("Twilio", "TO")
txt_from = configurations.get("Twilio", "FROM")
twilio = Client(twilio_account, twilio_token)
# print(twilio_account, twilio_token, txt_to, txt_from)

# Imgur setup
imgur_id = configurations.get('Imgur', 'CLIENT_ID')
imgur_secret = configurations.get('Imgur', 'CLIENT_SECRET')
imgur_access = configurations.get('Imgur', 'ACCESS_TOKEN')
imgur_refresh = configurations.get('Imgur', 'REFRESH_TOKEN')
imgur = ImgurClient(imgur_id, imgur_secret, imgur_access, imgur_refresh)
imgur_config = {
'album': None,
'name': 'Intruder!',
'title': 'Intruder!',
'description': 'Possible Intruder'
}
# print(imgur_id, imgur_secret, imgur_access, imgur_refresh)

def isHome():
# This function returns true if the mac address registered is scanned
# on the wifi, false otherwise.
def is_home():
global network
global last_scan
# Check if this is the first run or if the last network scan occured
Expand All @@ -29,42 +60,57 @@ def isHome():
print(network)
# a timer to make sure the arp-scan was finished
# time.sleep(30)

if address in network:
print(individual + " is home")
return True
else:
print("No one is home")
return False


# This function takes a picture of an intruder, returns true if successful
# and false otherwise
def take_picture():
picture = subprocess.run("fswebcam " + picture_path, shell=True, check=True)
return os.path.isfile(picture_path)


# Twilio setup
account = 'secret'
token = 'secret'
txt_to = 'secret'
txt_from = 'secret'
twilio = Client(account, token)
# This function uploads an image located at the default location to Imgur and
# returns the url, otherwise it returns none
def upload():
image = imgur.upload_from_path(picture_path, config=imgur_config, anon=True)
os.remove(picture_path)
return image["link"]


# This function sends an alert to the registered phone number
def send_text(url):
text = "Intruder detected! Check out the intruder at " + url
message = twilio.messages.create(to=txt_to, from=txt_from, body=text)

def send_text():
text = 'Intruder detected!'
if not isHome():
message = twilio.messages.create(to=txt_to, from_=txt_from, body=text)
else:
print("Individual is home, no text will be sent")
isOpen = 0
oldIsOpen = None

# If the script will be run on boot, the following line will give the Pi
# time to connect to the network
# sleep(60)
isOpen = 0
oldIsOpen = None

while True:
oldIsOpen = isOpen
isOpen = GPIO.input(DOOR_SENSOR_PIN)
print(isOpen)
# print(isOpen)

if (isOpen and (isOpen > oldIsOpen)):
send_text()
print("Door opened!")
if not is_home():
if take_picture():
url = upload()
send_text(url)
else:
print("Unable to take a picture")
else:
print(individual + " is home, no text will be sent")


time.sleep(0.1)