Search This Blog

Tuesday, October 10, 2017

How to view pictures from the motion detection on Raspberry pi using motion.conf

Your pictures will be saved in /tmp/motion by default.

Create an alias on apache2 virtual host section on the conf file.

just after /var/www directory directive.

////////////

Alias /images /tmp/motion
<Directory /tmp/motion>
Options Indexes FollowSymLinks MultiViews
    Order allow,deny
    Allow from all
  </Directory>

///////////////////////////

Make another file called list.html and put it in the var/www the default doc root for apache.

here is the code for that file.

////////////////////////////////////



<!DOCTYPE html>
<html>
<head>
<script>
var folder = "images/";

$.ajax({
    url : folder,
    success: function (data) {
        $(data).find("a").attr("href", function (i, val) {
            if( val.match(/\.(jpe?g|png|gif)$/) ) { 
                $("body").append( "<img src='"+ folder + val +"'> -->" );
            } 
        });
    }
});
</script>
</head>
<body>


</body>
</html>

////////////////////////////////////

Make sure your /tmp/motion has 755 chmod.

Now restart apache2 and you should see the recent motion detected jpgs on the html browser as shown below.

Also set a cron on the pi to rotate the pictures folder every day or week so that you dont fill up your sdcard.

To find out how to expose this cam running on motion via pi, checkout my earlier tutorial where i explained port forwarding and duckdns.

Monday, October 9, 2017

How to get a public ip for a home camera running on Raspberry pi using motion.conf

IF you have attached a USB webcam to your PI and thinking to view it over the internet here is the way to do it.

Go to duckdns.org and login and get a url and the token.

Go to you pi and create a duckdns.sh script as shown below.

echo url="https://www.duckdns.org/update?domains=nameofcam&token=token&ip=" | curl -k -o /root/test/duckdns/duck.log -K -


Now go to crontab and create a cron entry like this.

*/5 * * * * /root/test/duckdns/duck.sh >/dev/null 2>&1

crontab reload

Make sure script has execute permissions.

Now test the url you specified in duckdns , you should see your camera ip being updated every minute.
Make sure you do a port forward on your router to the wlan ip of the camera.