Giter VIP home page Giter VIP logo

ellistheellice / raspi-alarm Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 78.55 MB

This is a small home-made alarmsystem based on a raspberry pi. The alarmsystem is able to detect motion through a PIR-sensor. If a motion is detected, the raspberry starts taking images from the suspicious movements. Those images are then immediately backed-up to AWS S3, so that in case the raspberry gets destroyed, some images have made it to the backup. In addition to this, the raspberry sends a notification to an AWS SNS topic, so that the owner can get notified in multiple ways (email, SMS, Push etc.).

Java 80.53% CSS 1.71% HTML 16.26% PHP 1.50%

raspi-alarm's Introduction

raspi-alarm

This is a small home-made alarmsystem based on a raspberry pi. The alarmsystem is able to detect motion through a PIR-sensor. If a motion is detected, the raspberry starts taking images from the suspicious movements. Those images are then immediately backed-up to AWS S3, so that in case the raspberry gets destroyed, some images have made it to the backup. In addition to this, the raspberry sends a notification to an AWS SNS topic, so that the owner can get notified in multiple ways (email, SMS, Push etc.).

If you have the possibility to run a web application, here are some good news: I have included a simple webapp which can run on a webserver and viewed on a smartphone. With this webapp, it is possible to start or stop the alarmsystem without the need to SSH into your raspberry. Of course it is possible to run this webapp on the raspberry itself. The installation section covers how to do that.

Using AWS services implies costs. They are really low, but they will occur. See here for pricing of the used services:

Version

0.0.1

Raspberry version

Tested on

  • Model B Rev.2

Table of contents

  1. Used Tech
  2. Setting up the raspberry camera
  3. Setting up the raspberry
  4. Setting up the raspberry 433Mhz module
  5. Setting up AWS
  6. Setting up the app
  7. Setting up Netbeans for development

Used Tech

The project in written in Java and makes use of the following technologies:

Installation

Setting up the raspberry camera

First of all, you have to connect the camera to the raspberry pi. The following pages give instructions on how to do that:

Setting up the raspberry

  • Wifi connection
  • wiring pi
$ sudo apt-get install git-core 
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build
  • pilight

Setting up the raspberry 433Mhz module

To switch on lights in an event of suspicious movement, we need radio-controllable plugs and radio sender for raspberry pi. This page explains how to set it up on the raspberry (Step 4).

Setting up AWS

Before coming to the required AWS services, you need to have an AWS account. See here for more information on what AWS is and how to create an account.

Once you have an account, log in and do the following.

SNS

  1. Move to the SNS service section

  1. Click on "Create topic"

  1. Specify a Topic name and a Display name and click on "Create topic"

  1. Now, click on "Create subscription"

  1. Specify the way you want to get informed. In this case, I wanted to get informed by SMS, but email is also possible.

Once done, you will receive a message to confirm the subscription. After you have confirmed it, you´re good to go.


S3

  1. Move to the S3 service and click on "Create bucket" to create a bucket. Give it a name and save it.

  1. Make sure you note down the region and the bucketname as they will be required later

IAM

Now that we have our services in place, we need to create a user with access permissions to the created recssources.

  1. Switch to the IAM service, click on "Users" and click "Add user".

  1. Specify a username, check the "Programmatic access" checkbox and click "Next: Permissions".

  1. Click on "Attach existing policies directly", search for "Amazons3FullAccess" and check it.

  1. Now search for "SNSFullAccess" and check it. Click "Next: Preview"

  1. Click on "Create user".

  1. Note down your Access key ID and your Secret access key


Now that you have the access key id and the secret access key, you have to place your credentials on the raspberry. Create a credentials file in the pi users home dir:

$ mkdir /home/pi/.aws
$ nano /home/pi/.aws/credentials

The files conten should looks as follows:

[default]
aws_access_key_id=<your-key-here>
aws_secret_access_key=<your secret here>

Setting up the app

Install the alarmsystem

Some time ago, Oracle announced a JDK which runs on ARM processors,which enables the raspberry to run java programs. Together with the Pi4J library, it is possible to directly access GPIO connected devices. To install java, simply execute the following steps:

$ sudo apt-get install oracle-java8-jdk

Before you will be able to execute the alarmsystem project, you have to compile it. Execute the following steps to do so:

$ sudo apt-get update 
$ apt-get install git
$ git clone https://github.com/EllisTheEllice/raspi-alarm
$ cd raspi-alarm
$ wget http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
$ tar -xzf apache-maven-3.5.4-bin.tar.gz
$ export PATH=$PATH:/home/pi/raspi-alarm/apache-maven-3.5.4/bin
$ export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt
$ cd alarmsystem

Before you compile, you should have a look at the src/main/java/github/ellisthealice/alarmsystem/util/Props.java file so that it fits to your environment. After that, you can compile:

 $ mvn clean install

Now, let´s create a service. This will be needed to autostart the alarmsystem after errors as well as for the webapp.

$ cd ../
$ sudo cp linux/alarmsystem.service /etc/systemd/system/
$ sudo systemctl deamon-reload
$ sudo systemctl enable alarmsystem.service
#Now you should be able to start the service
$ sudo systemctl start alarmsystem.service
# You can check the status
$ sudo systemctl status alarmsystem.service
# You can also check the logs
$ ls /var/log/alarmsystem

Install the webapp

SSH into your raspberry pi and execute the following commands to install apache along with PHP:

$ sudo apt-get update
$ sudo groupadd www-data
$ sudo usermod -a -G www-data www-data
$ sudo nano /etc/apt/sources.list
#Now, add the folowing line to it at save the file:
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
#Edit your preferences to control how apt-get updates its packages
$ sudo nano /etc/apt/preferences
    Package: *
    Pin: release n=jessie
    Pin-Priority: 600
$ sudo apt-get update
#Now install apache and PHP
$ sudo apt-get install -t stretch apache2 -y
$ sudo apt-get install -t stretch php7.0 php7.0-curl php7.0-fpm php7.0-cli php7.0-opcache php7.0-json -y
$ sudo apt-get install -t stretch libapache2-mod-php7.0 -y

#Make the pi user part of the www-data group
$ sudo usermod -a -G www-data pi

#To allow the www-data user to start/stop the service created above, do the following
$ sudo visudo

Add these lines:

www-data ALL=(ALL:ALL) NOPASSWD: /bin/systemctl start alarmsystem
www-data ALL=(ALL:ALL) NOPASSWD: /bin/systemctl stop alarmsystem

Caution: Editing the sudoers file can harm the system. Please make sure you are aware of possible problems!

Now that apache and PHP are installed, you can bring the webapp to it. Copy the contents of the raspilot folder to your /var/www/html folder.

$ sudo cp raspilot /var/www/html/
$ sudo chown -R www-data:www-data /var/www/html/rapilot

You should now be able to visit the webapp using http://{raspi-ip}/raspilot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.