Giter Site home page Giter Site logo

orosandrei / home-monitoring-raspberry-pi-node Goto Github PK

View Code? Open in Web Editor NEW
50.0 8.0 22.0 1.16 MB

Raspberry Pi & Node.js diy Home Monitoring & Intruder Alert system

Home Page: http://orosandrei.github.io/Home-Monitoring-Raspberry-Pi-Node

License: MIT License

JavaScript 85.18% Shell 1.96% CSS 1.49% HTML 11.37%
raspberry-pi video-stream pir-sensor alarm webcam nodejs monitoring iot

home-monitoring-raspberry-pi-node's Introduction

Home Monitoring with Raspberry Pi and Node.js

Alt text

Description

The project is designed as a end to end solution for a DIY Home Monitoring & Intruder Alert system. Besides offering a live video stream on any device (web responsive client), it also actively monitors for movement with the help of a PIR sensor.

If an Alarm is triggered, you get a SMS notification on your phone and the snapshots taken during the Alarm time span (customizable - default is 1 minute) are uploaded via FTP to your server.

Activation / Deactivation of the Alarm Mode can be done in 2 ways:

  1. from the Web Client user interface
  2. with a Button - for convenience reasons: it is faster than connecting from your phone / pc & toggling the Alert Mode checkbox
    • there is a 10 seconds customizable delay which allows you to move out of the PIR sensor range
    • a Led indicates the Alarm Mode enabled/disabled status

In order to avoid false positives from the PIR motion sensor, extra checks were added - a detection counter & detection interval. The Alarm gets triggered when the sensor detects movement 3 times in 5 seconds (both values configurable in code).

Technology

The project was developed using:

  • Raspberry Pi - raspbian, brick button & led, Pir sensor
  • Node.js - for the main application
  • Mjpg_streamer - to generate the video stream
  • Shell scripting - for easy application start (interactive & background)
  • Htms/Css/Javascript + Bootstrap - the web client

Project components

Hardware

Alt text

this.Gpio = require('pi-gpio');
this.Hardware = { MotionSensor : 8, Led : 26, Button : 12 };
  • Raspberry Pi
    • I used Model B Revision 2 with Raspbian - any model should be Ok, just be careful with the Gpio configuration pin mappings, they can differ
    • Generic USB webcam (compatible with Raspberry Pi & Raspbian)
    • You can find a comprehensive list here http://elinux.org/RPi_USB_Webcams
    • I used a very old 2MP one which seems to work out of the box with the generic drivers
  • Led & Button
    Alt text
  • PIR motion sensor

Alt text

  • The one I used is available here https://www.sparkfun.com/products/13285
  • It normally connects to Analog Input (ex. on Arduino); however you can use it with Digital as well if you connect a 10K resistor between VCC & Signal
    Alt text
  • To make things easier you can purchase this sensor https://www.adafruit.com/products/189 and skip the soldering part (+ this one has configurable sensitivity built-in, so you might be able to skip the one implemented in the code)

Node application

Dependencies

  • express: ^4.12.3
  • ftp: ^0.3.10
  • http-auth: ^2.2.8
  • ini: ^1.3.4
  • pi-gpio: 0.0.7
  • socket.io: ^1.3.5
  • twilio: ^2.3.0

The dependencies you install with NPM:

npm install module --save

Generic Application.js

It is the basic application object, defined to be reusable in other projects Contains the basic server code, generic config file read/write operations, generic Init & Execute & Exit methods implementations

Home Monitoring ApplicationHM.js

  • config.ini file

    • default video quality & alert mode settings
    • Twilio sms Api Sid, Token, To number, From number
    • Ftp settings
  • Authentication (digest http authentication) - defaults are admin & password :)

    admin:Private:6982db7f1ddc36a0b47b5f8427dc3526
    
  • Web Client application

    • Accessible from anywhere via port forwarding
    • Available also on mobile (responsive web client)
  • Monitoring - gets video from Mjpg_streamer server and sends it to the connected app clients

  • Mjpg_streamer was used as server, but if you prefer another tool like ffmpeg, you can easily replace it because of the loose integration via the start-webcam.sh script

Alarm mode

  • Monitoring - via PIR sensor
  • Alarm - Sms notification (implemented with the help of Twilio text messaging API - very cool service, offers great Trial account for development
  • Alarm - Snapshots upload to server via Ftp

Web Client - responsive

The client application was designed to be accessible on all platforms (pc / tablet / mobile).

Alt text

Video streaming quality settings

By default the 480p at 25fps is enabled (initial settings are loaded from the config.ini file)

My webcam is a low-end 5+ years old 2mp device, but for those of you with better webcams I also added 720p & 1080p

Video resolutions & fps can be configured from the /static/js/script.js file

	ui.quality480p.change(function(){ ConfigUpdateQuality("640x480",25); });
	ui.quality720p.change(function(){ ConfigUpdateQuality("1280x720",15); });
	ui.quality1080p.change(function(){ ConfigUpdateQuality("1920x1080",5); });	

Alert Mode

  • initial state is loaded from the config.ini file
  • You can enable/disable monitoring from checkbox button in the UI
  • The state of the Alert Mode is shown both in the UI (the checkbox) but also by the LED
  • The physical Button can be also used to toggle the Alert Mode
  • All state changes are sent to all connected clients
  • If an Alarm is triggered, the UI checkbox button background will be changed to Red Alt text

Connected Clients

The dropdown shows a list of all connected clients (connection timestamp & IP) that are currently viewing the video stream
Alt text

Shell Scripts

start-app.sh

  • You can start the application in 2 modes:
    • Interactive (for dev / testing): ./start-app.sh
    • Background: ./start-app.sh -background
#!/bin/bash
# application start in interactive or background mode
#arguments:  [-background]

cd /home/pi/Desktop/rpiWorkspace/Node/HomeMonitoring/

if [ "$1" = "-background" ]; then
	sudo nohup node ./App-home-monitoring.js &>log.txt &
else
	sudo node ./App-home-monitoring.js 
fi

start-webcam.sh

  • Used by the application to enable/disable video streaming when clients are connected or when an Alarm is triggered by the PIR sensor.
#!/bin/bash
# webcam video stream
# arguments:  [resolution] [port] [fps]

pkill mjpg_streamer

sudo nohup ./mjpg-streamer/mjpg_streamer -i "./mjpg-streamer/input_uvc.so -y -r $1 -f $3 -q 75" -o "./mjpg-streamer/output_http.so -n -p $2" &

Application Execution Session example

Alt text


TO DO

  • Port the application to Windows 10 Iot on Raspberry Pi 2
  • Support for uploading snapshots to cloud (OneDrive / Dropbox) when an Alarm is triggered

References


Links

home-monitoring-raspberry-pi-node's People

Contributors

orosandrei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

home-monitoring-raspberry-pi-node's Issues

Switching back to lower resolution mode wasn't possible

There was a bug that would prevent going back to 480p once you switched to 720p (or back to 720p once you switched to 1080).

This should fix it: dejanpan@94ebdc2, however admitedly me being super newbie JS programmer there could be a better solution.

If you like this one or if you tell me how you wonna have it I can provide a proper PR.

Only getting half of the stream

Hi there!
I forked your project as it looks like the best end-to-end solution for what I wonna do. Great work.

However I am hitting the wall right now. I got PI camera and I only wanted to get the video streaming done first, so I mostly commented out everything else in https://github.com/dejanpan/Home-Monitoring-Raspberry-Pi-Node/blob/master/App-home-monitoring.js.

The problem that I am having is that in resolution 640x480, 75% quality I only get parts of the image:
screen shot 2016-07-13 at 22 09 02

If I reduce the quality of the image I get more. It seems that the frames are coming from the stream in chunks here: https://github.com/dejanpan/Home-Monitoring-Raspberry-Pi-Node/blob/master/App-home-monitoring.js#L221 but I do not really know how to compose them together. E.g. when do I know 1 frame has been fully transferred to that callback?

Any hints I would warmly appreciate.

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.