Sunday, 13 April 2014

Arch Linux Raspberry Pi Monitoring Webcam Setup



The following method describes how to set-up a webcam that can be used on Arch Linux. Its useful to already have :

  • NTP configured and running
  • Configured correct timezone e.g.
$ sudo ln -s /usr/share/zoneinfo/America/Toronto /etc/localtime
  • Update the latest packages
$ sudo pacman -Syu 

Webcam Setup

  • Connect the webcam to the USB port
  • You should see it listed under :
 $ sudo lsusb
Bus 001 Device 004: ID 19ff:0102 Dynex 1.3MP Webcam


  •  If the camera is not listed check dmesg
$ dmesg | tail
[    5.401492] uvcvideo: Found UVC 1.00 device Dynex 1.3MP Webcam (19ff:0102)
[    5.414733] input: Dynex 1.3MP Webcam as /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/input/input0
[    5.414990] usbcore: registered new interface driver uvcvideo



Install Motion


  • Motion is a software motion detector which grabs images from video4linux devices and/or from webcams

$ pacman -S motion

  • This will install ~116MB of sotfware and dependacies 

Install ffmpeg


  • Ffmpeg is a complete and free Internet live audio and video broadcasting solution for Linux

$ pacman -S ffmpeg

  • This will install ~30MB of sotfware and dependacies 

Create log

  • Create the log file under /var/log

$ sudo touch /var/log/motion.log
$ sudo chmod 777 /var/log/motion.log

Motion Configuration


  • Backup existing config file :

$ sudo cp /etc/motion/motion.conf /etc/motion/motion.backup 

  • Change /etc/motion/motion.conf file with the following as an example :

daemon off
minimum_frame_time 0
pre_capture 0
post_capture 0
output_normal on
quality 75
ffmpeg_cap_new off
ffmpeg_timelapse 0
ffmpeg_variable_bitrate 0
target_dir /data/webcam/motion
webcam_port 8081
control_port 8080
webcam_localhost off
width 320
height 240



  • target_dir : target base directory for pictures 
  • Create target base directory for pictures

$ sudo mkdir -p /data/webcam/motion

  • Start motion and go to port 8081 of your local IP and the web cam should be working :

$ sudo motion &

Startup Script


  • Example Startup script


$ cat StartWebCamMonitor.sh
#!/bin/bash
LOG=/var/log/motion.log
sudo echo "Start Motion Script" `date` >> /var/log/motion.log
sudo /usr/bin/motion 2>&1 | tee -a $LOG &



Shutdown Script


  • Example Shutdown script

$ cat StopWebCamMonitor.sh
#!/bin/bash
LOG=/var/log/motion.log
# Script details
sudo echo "Stop Motion Script" `date` >> /var/log/motion.log
sudo pkill motion 2>&1 | tee -a $LOG

 

Clean Up Script

  • Example Clean up script
$ cat CleanUpWebCamMonitor.sh
#!/bin/bash
> /var/log/motion.log
sudo rm -rf /data/webcam/motion/
sudo mkdir /data/webcam/motion/


 Schedule WebCam to Run daily

  • Use 'crontab -e' to update when you want the scripts to run
$ crontab -l
00 07 * * 1-5 ~/bin/StartWebCamMonitor.sh > /dev/null 2>&1 &
00 19 * * 1-5 ~/bin/StopWebCamMonitor.sh > /dev/null 2>&1 &
20 19 * * 1-5 ~/bin/CleanUpWebCamMonitor.sh > /dev/null 2>&1 &







No comments:

Post a Comment