stevepedwards.com/DebianAdmin linux mint IT admin tips info

Pi3 USB Boot Device with Picam Motion

Don't use

auto_brightness on

with the newer Motion! It pulses dark/light like the Pi2s with older motion can.

There are different terms for some of the same parameters in the newer Motion version conf, so older Pi2 conf files won't work and break motion if used. However, once identified by line comparison of the old to new, same settings for these newer terms can be used.

See my old Post:

https://www.stevepedwards.com/DebianAdmin/pi-with-motion-only-minimal-fresh-install-summary/

sudo apt-get install motion

Setting up motion (4.0-1) ...
Adding group `motion' (GID 115) ...
Done.
Warning: The home dir /var/lib/motion you specified already exists.
Adding system user `motion' (UID 109) ...
Adding new user `motion' (UID 109) with group `motion' ...
The home directory `/var/lib/motion' already exists. Not copying from `/etc/skel'.
adduser: Warning: The home directory `/var/lib/motion' does not belong to the user you are currently creating.
Adding user `motion' to group `video' ...
Adding user motion to group video
Done.
Setting up libavdevice57:armhf (7:3.2.5-1) ...
Setting up ffmpeg (7:3.2.5-1) ...
Processing triggers for libc-bin (2.24-11+deb9u1) ...
Processing triggers for systemd (232-25+deb9u1) ...

Note the info above for changes - first add stevee to motion group!

stevee@pi3:~ $ sudo adduser stevee motion
sudo: unable to resolve host pi3
Adding user `stevee' to group `motion' ...
Adding user stevee to group motion
Done.

Just turning the basic defaults on, what happens in the new version?

I enabled the camera in sudo raspi-config.

stevee@pi3:~ $ sudo vi /etc/motion/motion.conf

daemon on

stevee@pi3:~ $ sudo vi /etc/default/motion

start_motion_daemon=yes

stevee@pi3:~ $ sudo motion
sudo: unable to resolve host pi3
[0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started
[0:motion] [NTC] [ALL] create_path: creating directory /var/log/motion
[0:motion] [NTC] [ALL] motion_startup: Logging to file (/var/log/motion/motion.log)

The default port is 8081 so try a browser view:

This site can’t be reached

192.168.1.13 refused to connect

Restrict stream for localhost only needs to be off in motion.conf:

stream_locahost off

stevee@pi3:~ $ sudo service motion restart

Broadcast message from systemd-journald@pi3 (Thu 2017-10-05 18:45:01 BST):

motion[2137]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

Message from syslogd@pi3 at Oct 5 18:45:01 ...
motion: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

Check if /var/log/motion/motion.log exists:

stevee@pi3:~ $ ls -l /var/log/motion/motion.log
-rw-r--r-- 1 root root 11839 Oct 5 18:45 /var/log/motion/motion.log

Allow motion ownership of it :

stevee@pi3:~ $ sudo chown motion /var/log/motion/motion.log
sudo: unable to resolve host pi3
stevee@pi3:~ $ ls -l /var/log/motion/motion.log
-rw-r--r-- 1 motion root 11839 Oct 5 18:45 /var/log/motion/motion.log

stevee@pi3:~ $ sudo service motion restart
sudo: unable to resolve host pi3

Root can run motion but user cannot;

stevee@pi3:~ $ motion
[0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started
[0:motion] [ERR] [ALL] myfopen: Error opening file /var/log/motion/motion.log with mode a: Permission denied
[0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

Broadcast message from systemd-journald@pi3 (Thu 2017-10-05 19:35:41 BST):

motion[2736]: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

stevee@pi3:~ $ ls -l /var/log/motion/motion.log
-rw-r--r-- 1 motion root 13687 Oct 5 19:34 /var/log/motion/motion.log

motion group setting needs 775 for user and group access to write to log:

stevee@pi3:~ $ sudo chmod 775 /var/log/motion/motion.log
sudo: unable to resolve host pi3

Message from syslogd@pi3 at Oct 5 19:35:41 ...
motion: [0:motion] [EMG] [ALL] motion_startup: Exit motion, cannot create log file /var/log/motion/motion.log: Permission denied

Check camera is working:

stevee@pi3:~ $ sudo raspivid -o test.h264
sudo: unable to resolve host pi3

Camera flashed up on HDMI TV so is ok.

Check playback of file:

stevee@pi3:~ $ sudo apt-get install omxplayer

stevee@pi3:~ $ sudo omxplayer test.h264

Views on TV ok.

BUT user cannot access camera:

stevee@pi3:~ $ raspivid -o test.h264
* failed to open vchiq instance

stevee@pi3:~ $ sudo chmod 777 /dev/vchiq
sudo: unable to resolve host pi3
stevee@pi3:~ $ raspivid -o test.h264
mmal: main: Error opening output file: test.h264
No output file will be generated

That's because it can't overwrite root's prior file - but camera showed on TV so user can use it.

stevee@pi3:~ $ rm test.h264
rm: remove write-protected regular file 'test.h264'?

Now user can make and view test file.

stevee@pi3:~ $ nmap 127.0.0.1

Starting Nmap 7.40 ( https://nmap.org ) at 2017-10-05 19:17 BST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00031s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
139/tcp open netbios-ssn
445/tcp open microsoft-ds

8080/tcp open http-proxy
8081/tcp open blackice-icecap

Now the webserver is running but no camera image in browser as driver is not loaded.

stevee@pi3:~ $ sudo modprobe bcm2835-v4l2

stevee@pi3:~ $ lsmod | grep v4l
bcm2835_v4l2 44759 1
videobuf2_vmalloc 5920 1 bcm2835_v4l2
videobuf2_v4l2 17077 1 bcm2835_v4l2
videobuf2_core 34083 2 bcm2835_v4l2,videobuf2_v4l2
v4l2_common 6284 1 bcm2835_v4l2
videodev 184712 5 v4l2_common,videobuf2_core,bcm2835_v4l2,videobuf2_v4l2

Add "bcm2835_v4l2" to modules to load at boot:

sudo vi /etc/modules

stevee@pi3:~ $ sudo service motion restart

Working!

Set to run at boot:

stevee@pi3:~ $ sudo update-rc.d motion enable

Now you can tweak the conf details to suit your view resolution (960,720 etc), net shares, video access, jpg removal as in prior Post etc.

To Compare Old Confs With New

copy the newer tweaked motion.conf to my laptop I need to setup the samba share anyway for video access:

sudo vi /etc/samba/smb.conf (set homes section for shares and access perms; add [Share] section):
[Share]
path = /Share
writable = 1
browsable = 1
sudo mkdir /Share/ (folder for net access and motion vids)
sudo mkdir /Share/motion (folder for motion vid creation set in motion.conf)
sudo chown stevee.motion /Share/ -R (main net access user/owner and group)
sudo chmod 775 -R /Share/ (allows access to user stevee and his group, traversal for others)
sudo service samba restart (get changes read)

sudo smbpasswd -a stevee
New SMB password:
Retype new SMB password:
Added user stevee.

Now I can export the conf file to this directory and copy it to my laptop home dir:

stevee@pi3:~ $ sudo cp -v /etc/motion/motion.conf /Share/
'/etc/motion/motion.conf' -> '/Share/motion.conf'

Diffs between my old motion.conf files compared to the tweaked new Pi3 conf file are:

stevee@AMDA8 ~/Documents $ grep -Ev '^#|^$' motiongate.conf > gate.txt
stevee@AMDA8 ~/Documents $ grep -Ev '^#|^$' motionpi3.conf > pi3.txt
stevee@AMDA8 ~/Documents $ diff gate.txt pi3.txt

The left chevrons are Pi2 and right chevrons are Pi3 lines:
2c2
< process_id_file /var/run/motion/motion.pid
---
> process_id_file /var/run/motion/motion.pid
3a4,6
> logfile /var/log/motion/motion.log
> log_level 6
> log_type all
5c8
< v4l2_palette 8
---
> v4l2_palette 17
7,8c10
< / The video input to be used (default: 8)
< input 8
---
> input -1
10a13
> power_line_frequency -1
15a19,26
> ; netcam_url value
> ; netcam_userpass value
> netcam_keepalive off
> ; netcam_proxy value
> netcam_tolerant_check off
> rtsp_uses_tcp on
> ; mmalcam_name vc.ril.camera
> ; mmalcam_control_params -hf
20a32,34
> roundrobin_frames 1
> roundrobin_skip 1
> switchfilter off
25,26c39,40
< despeckle EedDl
< area_detect 12345679
---
> despeckle_filter EedDl
> ; area_detect value
33,39c47,51
< gap 60
< max_mpeg_time 0
< output_all off
< area_detect 12345679
< ; mask_file value
< output_normal first
< output_motion off
---
> event_gap 60
> max_movie_time 0
> emulate_motion off
> output_pictures on
> output_debug_pictures off
41,43c53,55
< ppm off
< ffmpeg_cap_new on
< ffmpeg_cap_motion off
---
> picture_type jpeg
> ffmpeg_output_movies on
> ffmpeg_output_debug_movies off
46c58
< ffmpeg_bps 500000
---
> ffmpeg_bps 400000
49c61,66
< ffmpeg_deinterlace off
---
> ffmpeg_duplicate_frames true
> use_extpipe off
> ;extpipe mencoder -demuxer rawvideo -rawvideo w=%w:h=%h:i420 -ovc x264 -x264encopts bframes=4:frameref=1:subq=1:scenecut=-1:nob_adapt:threads=1:keyint=1000:8x8dct:vbv_bufsize=4000:crf=24:partitions=i8x8,i4x4:vbv_maxrate=800:no-chroma-me -vf denoise3d=16:12:48:4,pp=lb -of avi -o %f.avi - -fps %fps
> ;extpipe x264 - --input-res %wx%h --fps %fps --bitrate 2000 --preset ultrafast --quiet -o %f.mp4
> ;extpipe mencoder -demuxer rawvideo -rawvideo w=%w:h=%h:fps=%fps -ovc x264 -x264encopts preset=ultrafast -of lavf -o %f.mp4 - -fps %fps
> ;extpipe ffmpeg -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -i pipe:0 -vcodec libx264 -preset ultrafast -f mp4 %f.mp4
51c68,69
< locate off
---
> locate_motion_mode off
> locate_motion_style box
53c71
< text_left GATE
---
> text_left PI3
56,60c74,79
< text_double on
< target_dir /Share/motion
< ;snapshot_filename %v-%Y%m%d%H%M%S-snapshot
< ;jpeg_filename %v-%Y%m%d%H%M%S-%q
< movie_filename %v-%Hhr%Mmins_%Ssecs_%d_%m_%Y
---
> text_double off
> ;exif_text %i%J/%K%L
> target_dir /var/lib/motion
> snapshot_filename %v-%Y%m%d%H%M%S-snapshot
> picture_filename %v-%Y%m%d%H%M%S-%q
> movie_filename %v-%Y%m%d%H%M%S
62,71c81,95
< webcam_port 8081
< webcam_quality 50
< webcam_motion on
< webcam_maxrate 5
< webcam_localhost off
< webcam_limit 0
< control_port 8080
< control_localhost off
< control_html_output on
< ; control_authentication username:password
---
> ipv6_enabled off
> stream_port 8081
> stream_quality 50
> stream_motion on
> stream_maxrate 1
> stream_localhost off
> stream_limit 0
> stream_auth_method 0
> ; stream_authentication username:password
> ; stream_preview_scale 25
> ; stream_preview_newline no
> webcontrol_port 8080
> webcontrol_localhost on
> webcontrol_html_output on
> ; webcontrol_authentication username:password
74,78c98,108
< ; track_port value
< track_motorx 0
< track_motory 0
< track_maxx 0
< track_maxy 0
---
> ;track_port /dev/ttyS0
> ;track_motorx 0
> ;track_motorx_reverse 0
> ;track_motory 1
> ;track_motory_reverse 0
> ;track_maxx 200
> ;track_minx 50
> ;track_maxy 200
> ;track_miny 50
> ;track_homex 128
> ;track_homey 128
87c117
< ; on_event_end rm -vr --i=no /Share/motion/*jpg
---
> ; on_event_end value
92,97c122,142
< on_movie_end rm -vr /Share/motion/*jpg --i=no
< on_camera_lost reboot
< ; thread /usr/local/etc/thread1.conf
< ; thread /usr/local/etc/thread2.conf
< ; thread /usr/local/etc/thread3.conf
< ; thread /usr/local/etc/thread4.conf
---
> ; on_movie_end value
> ; on_camera_lost value
> ; sql_log_picture on
> ; sql_log_snapshot on
> ; sql_log_movie off
> ; sql_log_timelapse off
> ; sql_query insert into security(camera, filename, frame, file_type, time_stamp, event_time_stamp) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')
> ; database_type value
> ; database_dbname value
> ; database_host value
> ; database_user value
> ; database_password value
> ; database_port value
> ; database_busy_timeout 0
> ; video_pipe value
> ; motion_video_pipe value
> ; camera /etc/motion/camera1.conf
> ; camera /etc/motion/camera2.conf
> ; camera /etc/motion/camera3.conf
> ; camera /etc/motion/camera4.conf
> ; camera_dir /etc/motion/conf.d

Just need to add those BOLD relevant settings from pigate.txt to the pi3 motion.conf, such as:

 on_movie_end rm -vr --i=no /Share/motion/*jpg

to remove the jpgs from the movie folder etc. at movie creation end and change the default target_dir directory to my Share:

target_dir /var/lib/motion

to

target_dir /Share/motion

I already changed the resolution from width/height 320/240 to 960/720...that's about it.

As you can see, most of the steps in my prior Post setup are the same.

The main one disallowed is echoing the driver into /etc/modules - it had to be added by vim for some reason...?

In future, remember that enabling the camera in raspi-conf doesn't load a v4l driver for motion!

If you wish to save the working image to a 2nd USB plugged into the Pi, Raspian dd now has a:

sudo dd if=/dev/sda of=/dev/sdb status=progress

option

My working Pi3 Motion conf is here:

Pi3working.txt

stevee@pi3:~ $ sudo grep -Ev "^[#;]|^$" /etc/motion/motion.conf

daemon on
process_id_file /var/run/motion/motion.pid
setup_mode off
logfile /var/log/motion/motion.log
log_level 6
log_type all
videodevice /dev/video0
v4l2_palette 17
input -1
norm 0
frequency 0
power_line_frequency 1
rotate 0
width 960
height 720
framerate 100
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
roundrobin_frames 1
roundrobin_skip 1
switchfilter off
threshold 10000
threshold_tune off
noise_level 32
noise_tune on
despeckle_filter EedDl
smart_mask_speed 0
lightswitch 0
minimum_motion_frames 5
pre_capture 0
post_capture 10
event_gap 60
max_movie_time 0
emulate_motion off
output_pictures on
output_debug_pictures off
quality 75
picture_type jpeg
ffmpeg_output_movies on
ffmpeg_output_debug_movies off
ffmpeg_timelapse 0
ffmpeg_timelapse_mode daily
ffmpeg_bps 500000
ffmpeg_variable_bitrate 0
ffmpeg_video_codec mpeg4
ffmpeg_duplicate_frames true
use_extpipe off
snapshot_interval 0
locate_motion_mode off
locate_motion_style box
text_right %Y-%m-%d\n%T-%q
text_left PI3
text_changes off
text_event %Y%m%d%H%M%S
text_double on
target_dir /Share/motion
movie_filename %v-%Hhr%Mmins_%Ssecs_%d_%m_%Y
timelapse_filename %Y%m%d-timelapse
ipv6_enabled off
stream_port 8081
stream_quality 50
stream_motion on
stream_maxrate 5
stream_localhost off
stream_limit 0
stream_auth_method 0
webcontrol_port 8080
webcontrol_localhost on
webcontrol_html_output on
track_type 0
track_auto off
track_iomojo_id 0
track_step_angle_x 10
track_step_angle_y 10
track_move_wait 10
track_speed 255
track_stepsize 40
quiet on
on_movie_end rm -vr --i=no /Share/motion/*jpg
on_camera_lost reboot

Also - to get rid of sudo: unable to resolve host PI3

sudo vi /etc/hosts

127.0.1.1 PI3

Comments are closed.

Post Navigation