PiKrellCam

PiKrellCam at RaspberryPi Forum

PiKrellCam at GitHub

Reducing Power Consumption

This is a work in progress. There’s not much “easy” about PiKrellCam.

Pseudo code for a Python script to watch for external commands, then execute them.

while true
    pause for 5min
    go read the text file
    set setEmail = n
    if text file line says "emailme" and sentEmail != y
        send email
        set sentEmail = y
    if text file line says "delsent" and sentEmail == y
        set sentEmail = n
end while

Start PiKrellCam from command line:

$ cd pikrellcam
$ pikrellcam  motion_enable on &

Use ampersand to get back to the prompt.

Create a shell script to delay start.

$ sudo nano startCam.sh

sleep 3m
/home/pi/pikrellcam/pikrellcam motion_enable on

 


 

I installed PiKrellCam last night, and it didn’t exactly go smoothly. It would help if I read through the 1000+ posts on the Pi Forum, but I didn’t have the patience. Instead, I followed the directions from the PiKrellCam Git Page, which says:

$ cd /home/pi
$ git clone https://github.com/billw2/pikrellcam.git
$ cd pikrellcam
$ ./install-pikrellcam.sh

Note that this will only work if you’re logged in as user: pi. It seems that the installer is configured for only a very specific circumstance, so don’t expect to install it somewhere else or use a different user. This may no longer be the case, according to later forum posts, but if you want the simplest installation, use the pi account.

At first, I wanted to download the file to my ~/Downloads directory, so that’s what I did. The problem is that when I installed it, it installed to that same directory, which is probably why it failed.

During the install, I specified a unique port and created a password. The install seemed to go well, but when I accessed the web page, it displayed: “No preview jpeg”. I tried starting the service using the Start button, but it didn’t do anything.

So then I followed the install directions exactly (logged in as pi and at /home/pi/), and it still didn’t work right at first. At the web page, it refreshed about three times per second and still did nothing – just jumped and jittered. I tried clicking the Start button – actually I started clicking all the buttons, but it was unresponsive. Then after a few minutes, I got an error page saying that my camera was being used by another application (no it wasn’t). (In retrospect, I think I probably clicked the Start button and didn’t wait long enough for it to engage.)

I rebooted and tried the web page again. This time, it displayed the preview and worked! Yay? I don’t like it when things break then just work.

To provide context, I was doing all this while being constantly interrupted by family. I suggest doing this in a quiet, secluded area when you have plenty of time to troubleshoot.

Questions I had/still have:

  • Where are the web pages stored?
    • ~/pikrellcam/www/
  • Does the install also install NGINX? or was it already there?
  • Is PHP installed already? I need to check.
  • How do I uninstall it?
  • How do I update it? – There’s an Update button on the web page.
  • How do you know what applications are installed, like mpack, ssmtp, php?

 

The application pages are written in PHP and JQuery.

I’m playing with it now. Let me say that the Motion Regions function is extremely useful. To view the saved motion regions, click List. By default, you will see only “default” that’s all there is.

To toggle the motion regions off, click Preset.

The documentation says to edit the ~/pikrellcam/pikrellcam.config file to add your email address, but there’s more to it than that. You need to first install SSMTP.

Change the Default File Save Location

Because PiKrellCam is going to write to a drive a lot, you will want to set up an alternate location for it. You want your OS micro SD card to last as long as possible, so you want to read and write to it as infrequently as possible.

/media/pi/SANDISK-16

Go get ourself a good-sized USB drive. I used a 16GB Sandisk.

From your Pi home directory:

$ cd .pikrellcam
$ sudo nano pikrellcam.conf

Search for the media_dir line and change it to a location on your USB drive.

media_dir /media/pi/SANDISK-16/PKC

When PiKrellCam first writes to that location, it creates a file structure:

/PKC
    /archive
    /stills
    /thumbs
    /timelapse
    /videos

Don’t forget to add an entry for your new USB drive in the Samba config file.

$ sudo nano /etc/samba/smb.conf
$ sudo /etc/init.d/samba restart

 

Notes from the Raspberry Pi Forum

To view errors:
/tmp/pikrellcam.log


Changing saturation on the NoIR, edit at-commands.conf and add in:
daily sunrise-5 “@saturation 99”
daily sunset+5 “@saturation -99”


I’ve only been able to get improvement by setting the video fps low at night (around 6 fps)


Those that want to change frame fps at night can put lines like this in ~/.pikrellcam/at-commands.conf:
# sunrise/sunset or dawn/dusk (times are reported in the log file)
# Motion is detected and preview updated at video_fps/mjpeg_divider so
# mjpeg_divider should be changed when video_fps is changed. Also change
# video_mp4_box to track video_fps or mp4 will be slow or fast motion.
#
# Adjust camera parameters in the evening: sunset{+-offset}
daily sunset “@exposure_mode night”
daily sunset+10 “@video_fps 4”
daily sunset+10 “@video_mp4box_fps 4”
daily sunset+10 “@mjpeg_divider 1”

# Adjust camera parameters in the morning sunrise{+-offset}
daily sunrise-10 “@video_fps 24”
daily sunrise-10 “@video_mp4box_fps 24”
daily sunrise-10 “@mjpeg_divider 4”
daily sunrise “@exposure_mode auto”


I do have it succesfully emailing me via the preview save script????


This doesn’t work – I tried to edit the pikrellcam.conf file and set media_dir to
media_dir /mnt/cam
A: can you check the symlink under /home/pi/pikrellcam/www – you should find media -> /mnt/cam
A: check to make sure you have write permissions.


After a reboot I have no preview of the camera in the webinterface
A: Go to the web UI System and push the Start button


To update:
cd ~/pikrellcam
git pull origin

Or just use the Update button on the web page.


If you ever run git and get an error like:
$ git pull origin
Updating e78deba..a6929d1
error: Your local changes to the following files would be overwritten by merge:
www/index.php
www/media.php
Please, commit your changes or stash them before you can merge.
Just delete www/index.php and www/media.php and run again: git pull origin.
Any change to a file made in ~/.pikrellcam will not be overwritten by an update.
Likewise, any edit or adding of a file in pikrellcam/scripts will not be overwritten.
Worst case would be you have to clean up and start over with a git clone. Every config file in ~/.pikrellcam/ will be safe and you can leave them alone if you have to do a new git clone.


How to kill
killall -9 pikrellcam


Email uses “mpack” an email application. To get the emailing you have to edit preview-save in the scripts directory and not the one in the scripts-dist directory. In the preview-save script uncomment the two lines:
mpack -s pikrellcam@$HOSTNAME $PREVIEW_JPEG $MY_EMAIL
echo “mpack -s pikrellcam@$HOSTNAME $PREVIEW_JPEG $MY_EMAIL” >> $LOG_FILE

and make sure the MY_EMAIL line has your correct email address. Finally, in pikrellcam.conf, this line must be set and not commented out:
on_motion_preview_save $C/preview-save $F $m $P $G


In case you want to save just the still image instead of the video to a remote site, you can do something like this:
/home/pi/pikrellcam/scripts/motion-end
#!/bin/bash

VIDEO_FILE=$1
FIFO=$2
LOG_FILE=$3

# construct still filename from video filename
F=$(basename $VIDEO_FILE .mp4).jpg
curl -T /home/pi/pikrellcam/media/stills/$F ftp://ftp.mysite.com/pics/$F –user USERNAME:PASSWORD


Parameters for motion_vectors_dimming and motion_area_min_side
The dimming is the percent to dim the jpeg stream when the show of motion vectors is enabled. If you want more contrast between the image and drawn motion vector squares, set the dimming lower. Set it higher if you want to see the image better, but less contrast is available for the vectors.

If motion vector count limit is set low, the size of the detected object can be very small and the blow up of that detected area for a thumb can be grainy or even missed since there can be some skew. Setting a minimum to the motion area side compensates for that. The units of the minimum is pixels.

Neither of these affect actual motion detection.


Web page password protection is now changed to use htpasswd.


Labels: Turn ON: Setup->Motion->Settings->Preview_Clean


Now there is a git “Upgrade” button on the web page for one click upgrades.


To directly email the still, you can use mpack like so ($s is last saved still):
on_still_capture mpack -s pikrellcam-still@$H $s user@gmail.com


The media_dir is configured in ~/.pikrellcam/pikrellcam.conf and you can have an automatic mount enabled in ~/pikrellcam/scripts/startup
For my setups, I leave the .pikrellcam.conf media_dir at its default of “media” and I edit the startup
script so that MOUNT_DISK=sda1
I have a USB stick plugged in which appears as /dev/sda so the startup script mounts /dev/sda1 on ~/pikrellcam/media and so all my video files are stored on the USB stick.


# crontab file
0 0 * * * find /home/pi/pikrellcam/media/archive -mtime +7 -exec rm {} \;


Recommended for low light (added these lines at at-commands.conf):
daily dusk “@brightness 50”
daily dusk “@video_fps 4”
daily dusk “@mjpeg_divider 1”
daily dusk “@mp4_box_fps 4”
daily dusk “@exposure_mode night”
daily sunrise “@brightness 50”
daily sunrise “@video_fps 24”
daily sunrise “@mjpeg_divider 6”
daily sunrise “@exposure_mode auto”


Streaming: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=400


On and off at terminal ?:
echo ‘motion_enable on’ >> /home/pi/pikrellcam/www/FIFO
echo ‘motion_enable off’ >> /home/pi/pikrellcam/www/FIFO


Some thoughts about security:
1. the .htpasswd shouldn’t reside inside the www root
auth_basic_user_file /home/pi/pikrellcam/www/.htpasswd;

2. the access to the .htpasswd should be denied by nginx configuration:
# deny access to .ht* files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}


#!/bin/bash

echo motion limits 12 12 > ~/pikrellcam/www/FIFO
echo motion burst 500 4 > ~/pikrellcam/www/FIFO

#If you want to configure a custom motions regions also:
#echo motion load_regions windy > ~/pikrellcam/www/FIFO

And when the weather gets back to normal, run something like this:
#!/bin/bash

echo motion limits 5 4 > ~/pikrellcam/www/FIFO
echo motion burst 200 3 > ~/pikrellcam/www/FIFO
#echo motion load_regions default > ~/pikrellcam/www/FIFO


I have a python program which monitors a sensor and then calls a shell script which does:
#!/bin/bash
echo “still” > /home/pi/pikrellcam/www/FIFO
echo “record on 4 4” > /home/pi/pikrellcam/www/FIFO

so I get a still image as well as a video showing before and after the trigger. There is about a half-second gap in the video right at the trigger, as the camera changes modes for the full-res still frame, but I think that’s a limitation of the GPU firmware and nothing to do with PiKrellCam.


jbeale’s complete pikrellcam.conf file:
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=450


Archive script
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=475
and a later version:
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=500
and:
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=800


Mount windows drive
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=500


How to change media location
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=525


I’m not sure about mpack usage of port 25, but /etc/ssmtp/ssmtp.conf needs to be setup to send to a mailhub that works with mpack.


If the mounting is done by pikrellcam by editing the ~/pikrellcam/scripts/startup script or by however you are doing the mounting, a umask should be specified for the mount.

For example, if you want pikrellcam to do the mounting of a FAT32 filesystem on /dev/sda1, uncomment the MOUNT_DISK=sda1 line in the startup script and change this line:
sudo mount $DISK_DEVICE $MEDIA_DIR

to

sudo mount -t vfat $DISK_DEVICE $MEDIA_DIR -o rw,user,umask=0002

Otherwise, however you are mounting the nas, you need the umask to be set.


Check if pikrellcam is running:
ps -e | grep pikrellcam


Check nginx:
sudo service nginx status

nginx.conf is now in /etc/nginx/


There are many ways to do this. What I do is have the Pi save files on the SD card short-term, then at some schedule (hourly, daily…) I use ‘rsync’ to copy the local Pi files to the remote server (could be another Pi or any other machine). Then I have separate ‘cron’ jobs on each machine that delete the oldest files to maintain a certain % disk usage or certain number of days. This is standard Unix/Linux file stuff, nothing specific to RPi. For example usage of ‘rsync’ try http://www.thegeekstuff.com/2010/09/rsy … d-examples or some other pages google will show.

The only trick here is that you need to set up the Pi to be able to ssh into the remote server without using a password, but that is easy to set up as explained here: http://www.thegeekstuff.com/2008/11/3-s … h-copy-id/
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=800


on_motion_begin $C/motion_send_alarm


What do you have configured for media_dir and archive_dir in pikrellcam.conf?
It looks like you should have:
media_dir /home/pi/shared/mount/pikrellcam/media
archive_dir /home/pi/shared/mount/pikrellcam/archive

The pikrellcam.conf values force the www directory links and manually changing them will not work. Pikrellcam tries to mount only if the MOUNT_DISK line in scripts/startup is uncommented.


Test www-data read/write access. Log in as root, then:
runuser -u www-data touch /home/pi/NAS/pikrellcam/media/testfile


add your NFS shares as
CODE: SELECT ALL
192.168.nfs.nfs:/shared /shared nfs defaults,noatime,x-systemd.automount 0 0


When I tried command line mpack it failed because ssmtp was not installed on this Pi.
A: ssmtp is just one way of configuring email sending in the console. There are other possible software like exim4 or postfix but i think ssmtp is a very easy way.


Make sure you are using an adequate power supply and a good USB cable


If you are running headless and don’t need the HDMI circuitry powered up, you can reallocate about 30mA to other resources by adding this line to your /etc/rc.local file:
/usr/bin/tvservice -o

You can also gain another 10mA by disabling the PIs power and act LEDs by adding the following to your /boot/config.txt file
# Disable the ACT LED.
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off

# Disable the PWR LED.
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off

Also disable the sound in your /boot/config.txt file since you aren’t really using it and it just uses more power and memory that the pi can use elsewhere.


After running several PiKrellCam devices for more than a year (starting when it was released in July 2015) I have come to the conclusion that flash memory (both microSD card, and USB stick) will likely become unreliable and fail after about a year of regular use recording motion video clips.

I moved /tmp and /var/log to a ramdisk because these are the most frequent written directories for the native linux system.

How to set these to RAM disk: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583&start=925


PiKrellCam will randomly spring into life for a while then stop
A: Could be inadequate power source.


 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s