Wednesday, July 26, 2017

Raspberry surveillance system, your house goes live on the internet

After leaving my brand new Raspberry 3 on the shelf for months (I admit being an impulsive buyer) I decided to give it some use by setting up a surveillance system with it. Raspberry 3 has more than enough power for easy image processing, and the camera developed for its GPU has nice quality at a very accessible price.

So, in order to start with this project, I got this PiCamera v2. I got that one with InfraRed (IR) filter, as I don't plan to take nightly shots with added IR lighting (maybe next prototype). It is really easy to connect its flex cable to the Raspberry (though unfortunately I'll have to leave the original case open and remove the top lid, as the case does not have a slot for the flex cable).

Once the camera is connected (beware to shut the system down before trying any connect/disconnect), I upgraded the whole Raspbian system with:

sudo apt-get update
sudo apt-get upgrade
sudo rpi-update

Now it's time to enable PiCamera module, this can be done by launching:

sudo raspi-config
Related option to toggle is under "Interfacing options".

Now that the camera is ready to be used, it's time to start playing with it. It is easy to take advantage of the official tool to take snapshots, raspistill.

You can take a snapshot with the bare:

raspistill -o pic.jpg
Ok, now we have everything to start playing seriously!

Next step is to install the bare minimum NGINX web server. Purpose of our prototype is to take a picture every n minutes, and show it on a web page hosted locally on your Raspberry and served by NGINX.

Before doing that, remember to:
  1. Make yourself with a dynamic DNS service, I tried Dynu which is free and easy to setup. Everything is clearly explained, you'll have to remember to setup "~/dynudns/" script with cron, which will update the dynamic DNS with your home IP. 
  2. Set a static IP for your Raspberry in your local network (e.g. 192.168.x.x)
  3. Log into you router configuration panel and set port forwarding to your Raspberry (port 8080 should reach the static IP set at previous step)
Once done, you'll probably be able to reach your third level chosen domain (e.g. "") and see the welcome page. Let's now change the HTML basic code under /var/www/html with something like:

<!DOCTYPE html>
<title>Welcome to my house!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<img src="my.jpg" alt="myhouse" style="width:100%;">

So this snippet is basically serving one picture captured by your PiCamera and stored locally to index.html file, this would be at "/var/www/html/my.jpg".

Last step is setting up a cron job with the related instructions to capture a periodical snapshot, this would be something like:

*/10 * * * * sudo raspistill -q 15 -w 1024 -h 768 -o /var/www/html/my.jpg

This will capture every 10 minutes a medium quality picture, quick to be served over the internet. Tune at your own preferred quality and capture rate!


  1. Nice answers in replace of the question with real point of view and explaining about that.
    security camera mounts

  2. I see the greatest contents on your blog and I extremely love reading them.
    car wash cameras

  3. Then add an extra line with the configuration of your Windows network shared folder: 2cd2h55 turret

  4. Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. must sell my Divorce house fast Des Moines Iowa

  5. One present why galore businesses opt for postcards is because they are overmuch cheaper to be prefab and this can forbear a lot of expenses on the lengthened run.  North Carolina Gutter Contracting company

  6. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work

  7. This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: Commercial Contractor Maryland

  8. This is extremely fascinating substance! I have completely delighted in perusing your focuses and have reached the conclusion that you are right about a hefty portion of them. You are extraordinary.  replacement windows london

  9. I am glad to get discovered this webpage Home Security Companies mainly because it helped me to make a decision. I chose ADT based upon their long standing yrs and track record of services in the industry.