Webcam Video Surveillance via Motion Debian Mipsel

If you own a webcam from this list than you can attach it to the AsusWRT routers usb port and capture images from it when motion is detected, like babyroom, garage, courtyard...

It's only for mipsel devices like RT-N16, RT-N66U, RT-AC66U...

1- Install Debian from here
2- Download videomod script

wget -c -O /opt/etc/videomod.sh http://goo.gl/tD4Q1p
chmod a+rx /opt/etc/videomod.sh

2a - Download and load UVC Modules

wget -c -O /opt/tmp/uvc_modules_2.6.22.19-378.50b2-mipsel.tar http://goo.gl/goAIjc
cd /
tar -zxf /opt/tmp/uvc_modules_2.6.22.19-378.50b2-mipsel.tar
/opt/etc/videomod.sh load

3 - Enter Debian

debian enter

4 - Update Debian

apt-get update
apt-get upgrade

5 - Install Motion

apt-get install motion

6 - Enable start

sed -i 's/start_motion_daemon=no/start_motion_daemon=yes/g' "/etc/default/motion"

7 - Fix start

sed -i 's/--chuid motion/--chuid root/g' "/etc/init.d/motion"

8 - Change download directory

sed -i 's/target_dir /tmp/motion/target_dir /mnt/motion/g' "/etc/motion/motion.conf"

9 -Exit debian

exit

10 - Rename original script and add it to chrooted services list

mv /opt/debian/etc/init.d/motion /opt/debian/etc/init.d/S90motion-debian
echo "" >>/opt/etc/chroot-services.list
echo "S90motion-debian" >>/opt/etc/chroot-services.list
chmod 755 /opt/etc/chroot-services.list

11 - Create script to load UVC Modules and motion at startup

nano /jffs/scripts/post-mount

Add this lines

#!/bin/sh
sleep 5
/opt/etc/videomod.sh load
sleep 10
/opt/etc/init.d/S99debian start

Save with CTRL-O / Enter / and exit with CTRL-X

chmod a+rx /jffs/scripts/post-mount

12 - Start motion

debian restart

13 - Perform a movement in the front of your webcam.

14 - Go to media folder you setup in S99debian script here at point 4 and you'll find pictures captured by webcam and some .swf files witch can be oppened with your internet browser.

 

Tested successfully with Logitech C270 webcam
c270

 

  • spindles7

    Many thanks for a great tutorial. I installed this on a RT-N66U running Asuswrt-Merlin 376.49_5 with a Logitech C270 webcam. Works great, but I did have problems initially getting the folder on the external drive to be mounted under /opt/debian/mnt. I found if I changed the line in /opt/etc/init.d/S99debian:

    from:
    [ -z "$EXT_DIR" ] || mount -o bind $EXT_DIR $CHROOT_DIR/mnt
    to:
    mount -o bind $EXT_DIR $CHROOT_DIR/mnt

    I could get it to work. Presumably the "[ -z "$EXT_DIR" ]" tests whether it's already mounted, but was succeeding even when it wasn't?

    The only issue I have now is that the router's CPU is always at 100% when motion (v3.2.12) is running. CPU load average (1, 5, 15 mins) is 1.26, 1.18 and 1.11 on my system. Is this normal? I am concerned it may affect performance of the router for it's day job!

    Great work.
    Roy

    • External folder should be just a folder not /mnt
      Do you have aicloud enabled? Another user reported high cpu with aicloud and another service, not motion.

      • spindles7

        Yes the external mount point is a folder. It's in a separate partition to where the code is. This is the output of df:
        Filesystem Size Used Available Use% Mounted on
        /dev/root 27.1M 27.1M 0 100% /
        tmpfs 117.0M 4.9M 112.1M 4% /tmp
        devfs 117.0M 0 117.0M 0% /dev
        /dev/mtdblock4 3.0M 452.0K 2.6M 15% /jffs
        /dev/sda1 2.0G 1.1G 790.5M 59% /tmp/mnt/entware
        /dev/sda2 227.2G 2.6G 213.1G 1% /tmp/mnt/media
        devfs 117.0M 0 117.0M 0% /tmp/mnt/entware/entware/debian/dev
        /dev/sda2 227.2G 2.6G 213.1G 1% /tmp/mnt/entware/entware/debian/mnt

        and EXT_DIR in S99debian is defined as :EXT_DIR=/tmp/mnt/media/Media

        where Media is a folder on the partition: media.

        No, aicloud is not enabled. The top utility shows high CPU 99% due to /usr/bin/motion. If I pause detection using the motion's web interface, the CPU load drops to around 50%. Now even after restarting detection, it's hovering around 50% but occasionally spikes up to 100. If I stop motion (using S99debian), the CPU drops to below 1%.

        Appreciate any pointers. Many thanks,
        Roy

      • I just check on my router and never go beyond 50% when motion is detected, after goes to 0%
        Do you have some other services running?

      • spindles7

        I've got exim4 running (to send emails when motion event starts) and have enabled samba from the web interface to access the shares from my desktop. Otherwise that's about it. Motion events are not frequent and CPU load is near 100% even when no movement is detected, which is most of the time. I am only saving jpeg files not videos, and only when motion is detected.

      • Did you reboot the router? If yes try to install from scratch.

      • spindles7

        Yes, have had to several times - don't know whether it's because of the high CPU load, but the router has started acting up resulting in no internet access, or no IP address from dchp. When I first had the problem, I deleted my first installation of debian and re-installed it with just exim4 as an additional package. Is it worth doing it again, including the entware part as well?

        One point on motion detection, initially I was getting almost constant motion events due to passing traffic on the road outside. So I added a mask to limit the detection area and this has cut it down dramatically and is only now triggered when someone or something (next door's cat for example!) enters my garden. Could that be a factor?

      • Cpu usage should be very low so it wort reinstalling.
        What kind of mask?

      • spindles7

        OK, will re-install and see what happens. The mask is a pgm file with areas I don't want any motion detected in black, the rest white. In motion.conf the value mask_file points to the file.

      • Send me pgm file and motion.conf to try on my router

      • spindles7

        OK, will do, but how can I attach files - the contact page won't let me attach the files either as they are or as a tar archive or a compressed archive - says file type not allowed.

      • I enabled following file types:
        [jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv|zip|tar|7z|rar|ipk|conf|json|txt|psd]
        Maximum file size is 10MB

      • spindles7

        Thanks for your email. Yes, reducing the resolution, and also the framerate (I had increased it to 5) has reduced the CPU load dramatically. I am actually running it now at 320x240 and a framerate of 2 fps.

        I did re-install from scratch as well, and noticed that in the instructions above to add lines to the /jffs/scripts/post-mount file, there was already some entries in there, so I added them immediately after the line:
        ln -sf $1/entware /tmp/opt
        and before the closing "fi". Is that correct?

        Many thanks for your help.

      • No, after entware script. Normally should be in services-start script but sometimes disk is not mounted in time and will never start, that's way I changed to post-mount.

        #!/bin/sh

        if [ $1 = "/tmp/mnt/sda1" ]
        then
        ln -sf $1/entware /tmp/opt
        fi

        swapon /opt/swap

        sleep 5
        /opt/etc/videomod.sh load
        sleep 10
        /opt/etc/init.d/S99debian start

SoftEther VPN Running on AsusWRT Routers
Minidlna UPnP Media Server through Debian Jessie Arm
How to Mount Samba Shares inside Chrooted Debian
Nginx Web Server with PHP Support through Optware-NG
Minidlna UPnP Media Server through Debian Jessie Arm
How to Mount Samba Shares inside Chrooted Debian
Spreed WebRTC server and web client
Asterisk VoIP Server running on AsusWRT Routers
SoftEther VPN Running on AsusWRT Routers
NZBGet through Entware
Minidlna UPnP Media Server through Debian Jessie Arm
NetData System Monitor Entware

SUBSCRIBE

To be notified by email when a new tutorial is posted :)

Thanks for Subscribing! I'll keeping you up-to-date with latest tutorials!

Something went wrong, try again...