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.

No comments:

Post a Comment