RPi-Cam-Web-Interface

RPi Cam Web Interface is a web interface for the RPi Cam that can be opened on any browser (smartphones included) and contains the following features:


 * View, stop and restart a live-preview with low latency and high framerate. Full sensor area available.
 * Control camera settings like brightness, contrast, ... live
 * Record full-hd videos and save them on the sd-card packed into mp4 container while the live-preview continues
 * Take single or multiple (timelapse) full-res pictures and save them on the sd-card (live-preview holds on for a short moment)
 * Preview, download and delete the saved videos and pictures, zip-download for multiple files
 * Trigger captures by motion detection
 * Trigger captures by many scheduling-possibilities
 * Circular buffer to capture the last actions afterwards
 * Control Pi-Pan and Pi-Light (http://www.openelectrons.com/Pi-Pan)
 * Shutdown/Reboot your Pi from the web interface
 * Show annotations (eg timestamp) on live-preview and taken images/videos

Remember, anyone can create an account on here and add to this wiki.

= Installation Instructions =

Basic Installation
Warning: The installer will replace various files, so backup all your data.

Step 1: Install Raspbian on your RPi

Step 2: Attach camera to RPi and enable camera support (http://www.raspberrypi.org/camera)

Step 3: Update your RPi with the following commands:

Step 4: Clone the code from github and run the installer with the following commands:

If you want to install the web interface in a subfolder of /var/www, edit "RPi_Cam_Web_Interface_Installer.sh" according to the comments in the file and run the installer. Otherwise directly run the installer:

Step 5: After the setup finishes, you have to restart your RPi. Now just open up any browser on any computer in your network and enter the IP of the RPi as URL.

Startup Behaviour
To change the default startup-settings, edit the config-file /etc/raspimjpeg. If you want to disable autostart completely, navigate back to the directory, where you cloned the git-repo in Step 4 and run one of the following command: ./RPi_Cam_Web_Interface_Installer.sh autostart_no --> the interface doesn't start at startup, you need to run a command to use it (commands below) ./RPi_Cam_Web_Interface_Installer.sh autostart_yes --> the interface starts at startup and takes control over the camera (standard)

To temporarily start/stop or deinstall: Navigate back to the directory, where you downloaded the installer in Step 4. If you want to stop the interface temporarily, run "./RPi_Cam_Browser_Control_Installer.sh stop". To restart it, run "./RPi_Cam_Browser_Control_Installer.sh start". If you want to remove the interface completely, run "./RPi_Cam_Browser_Control_Installer.sh remove". Attention: It removes all files in /var/www.

Links
Project itself: https://github.com/silvanmelchior/RPi_Cam_Web_Interface

RaspiMJPEG: https://github.com/roberttidey/userland/tree/master/host_applications/linux/apps/raspicam

Forum: http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276 PDF: https://github.com/silvanmelchior/RPi_Cam_Web_Interface/blob/master/RPiCam.pdf

Special thanks
To btidey for many, many new features

To jarrah31 for this wiki

To jonar for the github-repo

To James Cooke for the styling

To slabua for many fixes/improvements

To everybody else who helps on github, in the forum or here to develop the RPi Cam Web Interface

RTFM!
You can find answers to many of your questions in this very useful and detailed guide from Robert.

https://github.com/silvanmelchior/RPi_Cam_Web_Interface/blob/master/RPiCam.pdf

It also explains how everything works and includes a detailed list of scheduling commands and config information.

= Useful links to posts and additional information = This section will be updated to contain links to posts with useful information and answers to popular questions. Anyone can add to this, so please create an eLinux account and help contribute!

Scheduler
Some extra notes on the scheduler (Src: https://www.raspberrypi.org/forums/viewtopic.php?p=730220#p730220)
 * Scheduler calculates sunrise and sunset every Mode_Poll check interval.
 * A dawn start is then calculated by adding DawnStart_Minutes to sunrise (normally negative to make Dawn start before sunrise).
 * Similarly a Day start is sunrise + DayStart_Minutes.
 * Dawn is then the period from Dawn start till Day start.
 * Day then begins until sunset + DayEndMinutes.
 * Dusk then starts and continues to sunset + DuskEnd_Minutes.
 * Night then starts until the following Dawn.

The Config File
Thanks to the amazing hard work by Silvan Melchior, RaspiMJPEG now uses a config file to set various parameters on starting the RPi Can Web Interface.

/etc/raspimjpeg

The release update which includes an example of the config file can be found here: http://www.raspberrypi.org/phpBB3/viewtopic.php?p=524707#p524707

A few examples on how to set variables can be found below.

Changing the Field of View
(Perhaps redundant now that changing this option on the web interface stores the value when starting the camera again)

Follow this tutorial to start a different view automatically during boot:

There are three different preview modes available which are set by changing the resolution of the video_width and video_height options in the # Video Options section.

The view along with resolution is shown below: e.g. to set 4:3 full FOV:

Pi-Pan and Pi-Light
Information about Pi-Pan and Pi-Light: http://www.openelectrons.com/Pi-Pan‎

Needed Hardware for this addition:
 * Pi-Pan (OpenElectrons)
 * Pi-Light (OpenElectrons)
 * Pi-Case to mount Pi-Pan recommended (e.g. OpenElectrons)

With these code-changes and additions, it's possible to control Pi-Pan and Pi-Light from the RPi Cam Web Interface. Just follow these steps:


 * Assembly and install Pi-Pan: http://www.openelectrons.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=20
 * Check if pipan and pilight work with the scripts as described on the website
 * Run "sudo raspi-config", goto "Advanced Options", disable "Device Tree" and reboot
 * Add the file "pipan_pipe.py" to the pipan-files with the following content:


 * Navigate to "/var/www" and add a named pipe with the following commands:


 * Edit "/etc/rc.local": add the following line above the exit-command (change the path to the directory where you extracted the pipan-files):


 * Go to /var/www and rename the file "pipan_off" to "pipan_on" and "pilight_off" to "pilight_on"

That's it. After rebooting your Pi, you should be able to control Pi-Pan with the new Buttons "Up", "Down", "Left" and "Right" or on the keyboard with "W", "S", "A" and "D". The Pi-Light can be controled in the settings-table or on the keyboard with "F". If you have a touch-device (Android or iOS), you can pan/tilt by dragging the preview-image around. To change the minimum/maximum pan/tilt angles, edit the settings in /var/www/pipan.php.

Remote access to website with User/Pass and changing port
http://www.raspberrypi.org/forums/viewtopic.php?p=500460#p500460

If using motion you need to edit motion.conf adding the directive:

(source http://www.raspberrypi.org/forums/viewtopic.php?p=530057#p530057)

Central Motion Detection from Multiple Cams using iSpy Connect
http://www.raspberrypi.org/forums/viewtopic.php?p=518500#p518500

View video stream on an iDevice / Smartphone
Credit goes to Oke for the original post. A few more tweaks added for iPhone app. http://www.raspberrypi.org/phpBB3/viewtopic.php?p=507756#p507756

(note - cam.jpg created during the installation now)


 * Download "IP Cam View Pro" (I used IP Cam View Lite on the iPhone - can upgrade to Pro)
 * Select the menu icon
 * Press Manage Cameras
 * Select Add Camera then Generic URL
 * Give your cam a name
 * For Type choose Generic Video URL
 * Enter your URL, e.g. http://192.168.0.1:80/cam.jpg
 * Press Test
 * If it works, press Save

Embed live-preview in own homepage
This is the minimal code to embed the preview:

php:

js:

The size can be changed either as parameter in /etc/raspimjpeg or with CSS. To add further features (change settings, record images/videos), study the existing homepage.

Save an image upon motion detection
http://www.raspberrypi.org/forum/viewtopic.php?f=43&t=63276&start=175#p491013

Move saved images and videos to another folder
Detailed instructions on how to map a network NFS share to /var/www/media - http://www.raspberrypi.org/forums/viewtopic.php?p=531344#p531344

When to do the move - http://www.raspberrypi.org/forum/viewtopic.php?p=515967#p515967

Mounting a share - http://www.raspberrypi.org/phpBB3/viewtopic.php?p=513781#p513781

Mounting a Windows Share - http://www.stuffaboutcode.com/2012/05/raspberry-pi-connect-nas-windows-share.html

If you've mounted a network share to something other than /var/www/media, such as /mnt/myshare, you can bind the two together using this command:

Scale camera window correctly in Chrome on Android
http://www.raspberrypi.org/phpBB3/viewtopic.php?p=515786#p515786

Rotation not working?
Try a different browser - http://www.raspberrypi.org/forum/viewtopic.php?p=513705#p513705

Internet Explorer isn't supported, Opera and Firefox <21 can't show the preview of recorded videos.

Slow video stream?
http://www.raspberrypi.org/forum/viewtopic.php?p=513162#p513162

Overlay/Composite two images together
One way to add an image over the top of another is with ImageMagick. I've constructed a crude example below, and it works! But it bogs down the refresh rate, drives the load level to 1.5 and is barely acceptable. I'd like to toggle it on/off with a new button, and improve it's performance, so please edit this article better.