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:
- 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/dynu.sh" script with cron, which will update the dynamic DNS with your home IP.
- Set a static IP for your Raspberry in your local network (e.g. 192.168.x.x)
- Log into you router configuration panel and set port forwarding to your Raspberry (port 8080 should reach the static IP set at previous step)
<!DOCTYPE html>
<html>
<head>
<title>Welcome to my house!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<img src="my.jpg" alt="myhouse" style="width:100%;">
</body>
</html>
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!