Motion con Raspberry Pi Camera on board

Da raspibo.
Jump to navigation Jump to search

Installazione motion

sudo apt-get install motion

Perche` funzioni con la "raspi-cam" (la Camera on board ufficiale del Raspberry Pi), si deve caricare il modulo "bcm2835-v4l2", per farlo ad ogni avvio del Raspberry Pi, aggiungiamolo nel file "/etc/modules":

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

bcm2835-v4l2


Configurazione motion

La mia intenzione e` stata di non utilizzarlo da "root", ma da normale utente "pi", per cui ..

Ho creato la directory di lavoro nella directory utente "/home/pi" e ho copiato il file di configurazione d'esempio fornito con il pacchetto installato:

mkdir motion
cp /usr/share/motion/examples/motion-dist.conf motion/motion.conf

Ho modificato il file (motion/motion.conf) secondo le mie esigenze, riporto alcune delle impostazioni modificate (e/o controllate) a titolo d'esempio:

daemon off
process_id_file /home/pi/motion/motion.pid
setup_mode off
logfile /home/pi/motion/motion.log
log_level 6
log_type all
videodevice /dev/video0
v4l2_palette 15
input -1
norm 0
frequency 0
rotate 270
width 480
height 640
framerate 2
minimum_frame_time 0
netcam_keepalive off
netcam_tolerant_check off
rtsp_uses_tcp on
auto_brightness off
brightness 0
contrast 0
saturation 0
hue 0
power_line_frequency -1
roundrobin_frames 1
roundrobin_skip 1
switchfilter off
threshold 15000
threshold_tune off
noise_level 32
noise_tune on
lightswitch 0
minimum_motion_frames 1
pre_capture 0
post_capture 0
event_gap 60
max_movie_time 120
emulate_motion off
output_pictures on
output_debug_pictures off
quality 75
camera_id 0
picture_type jpeg
ffmpeg_output_movies on
ffmpeg_output_debug_movies off
ffmpeg_timelapse 0
ffmpeg_timelapse_mode daily
ffmpeg_bps 400000
ffmpeg_variable_bitrate 0
ffmpeg_video_codec mpeg4
ffmpeg_duplicate_frames off
use_extpipe off
snapshot_interval 0
locate_motion_mode off
locate_motion_style box
text_right %Y-%m-%d\n%T-%q
text_changes off
text_event %Y%m%d%H%M%S
text_double off
target_dir /home/pi/motion
snapshot_filename %Y%m%d%H%M%S-snapshot-%v
picture_filename %Y%m%d%H%M%S-%q-%v
movie_filename %Y%m%d%H%M%S-%v
timelapse_filename %Y%m%d-timelapse
stream_port 8081
stream_quality 50
stream_motion off
stream_maxrate 1
stream_localhost off
stream_limit 0
stream_auth_method 0
stream_preview_scale 25
stream_preview_newline off
webcontrol_port 8080
webcontrol_localhost off
webcontrol_html_output on
### Serve "mutt" configurato per l'invio della posta e la <MAIL> destinazione ###
on_picture_save echo "see attach" | mutt -s "$(hostname) alarm $(date +%F_%H-%M)" -a %f -- <MAIL>

Avvio motion

Non ho voluto usarlo come "daemon" vero e proprio, ma eseguirlo all'avvio del sistema, quindi ho inserito la linea di comando nel file "/etc/rc.local":

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

#
su -c "motion -n -c /home/pi/motion/motion.conf &" pi

exit 0


Utilizzo motion

Per il "controllo" web, collegatevi col browser agli indirizzi:

http://<IP o Nome del Raspberry Pi>:8080
per controllare/cambiare alcune impostazioni di configurazione (non l'ho provato)
http://<IP o Nome del Raspberry Pi>:8081
per visualizzare lo stream.


Note

Per teminare il programma usate il comando:

kill $(pidof motion)


Riferimenti

Motion-mmal_con_Raspberry_Pi_Camera_on_board