Skip to content

How to setup a schnaphoto host system on a Raspberry Pi

tgoerlich edited this page Feb 27, 2013 · 20 revisions

###1. Prerequisites:
Hardware:

  • a Raspberry Pi Model B (any version will do), that is connected to your home network via ethernet cable
  • an empty SDHC-card
  • a camera that supports remote operations via USB
  • a usb wifi-adapter that is compatible to the Raspi and supports host mode
  • a USB cable to connect your camera to the Raspi
    Skills:
  • some basic skills on the bash shell are required
  • if you have configured the apache webserver before, that will help
  • basic knowledge of a console text editor like vi or emacs are needed

###2. Install OS
Download (image) and install (instructions) the latest Raspian Wheezy

###3. basic settings
ssh in, run sudo raspi-config
execute command "update"
execute command "expand_rootfs"
execute command "change_pass"
execute command "change_locale" (change system language)
execute command "boot_behaviour", set "Should we boot straight to desktop?" to "No"
finish and reboot

###4. Update system:
become super-user:
sudo su
this updates the packaging index:
apt-get update
this installs all available package upgrades:
apt-get upgrade

###5. Install prerequisites
download and install some additional packages:
apt-get install apache2 hostapd hostap-utils iw dnsmasq udev udhcpd samba python-setuptools python-ctypeslib pyro python-daemon

###6. gPhoto 2.5: Download and install
As long as gPhoto 2.5 is not part of the Raspian distro, we need to download the sources and compile on our own.
If you are still root, return to normal user:
exit
install more prerequisites needed to compile gPhoto:
sudo apt-get install libltdl-dev libusb-dev libusb-1.0-0-dev libexif-dev libxml2-dev libpopt-dev
Figure out the latest release of the gPhoto suite (Sourceforge) and download:
wget http://downloads.sourceforge.net/project/gphoto/libgphoto/2.5.1/libgphoto2-2.5.1.tar.bz2
wget http://downloads.sourceforge.net/project/gphoto/gphoto/2.5.1/gphoto2-2.5.1.tar.bz2
unpack the tar balls:
tar -xjf libgphoto2-2.5.1.tar.bz2
tar -xjf gphoto2-2.5.1.tar.bz2
cd libgphoto2-2.5.1/
This will take a while:
./configure --prefix=/usr
Make sure to check the output carefully before you start the compilation process:
make
sudo make install
cd ../gphoto2-2.5.1/
./configure
make
sudo make install
check if installation was successful:
gphoto2 -v

   gphoto2 2.5.1
   
   Copyright (c) 2000-2013 Lutz Mueller and others
   
   gphoto2 comes with NO WARRANTY, to the extent permitted by law. You may
   redistribute copies of gphoto2 under the terms of the GNU General Public
   License. For more information about these matters, see the files named COPYING.
   
   This version of gphoto2 is using the following software versions and options:
   gphoto2         2.5.1          gcc, popt(m), exif, no cdk, no aa, no jpeg, no readline
   libgphoto2      2.5.1          all camlibs, gcc, ltdl, EXIF
   libgphoto2_port 0.10.0         gcc, ltdl, USB, serial without locking 

now grant all users r/w access to any usb device that is supported by gphoto:
sudo /usr/lib/libgphoto2/print-camera-list udev-rules version 0.98 group plugdev mode 0660 > /etc/udev/rules.d/90-libgphoto2.rules
restart udev daemon:
sudo /etc/init.d/udev restart

###7. configure apache:
vi /etc/apache2/sites-enabled/000-default
check and, if you like, change locations of docroot and cgi-bin directory
hint: if your arrow keys do not seem to work right within vi, try this vi command:
:set nocompatible

   <VirtualHost *:80>
   ServerAdmin webmaster@localhost

   DocumentRoot /home/pi/schnapphoto/www
   <Directory />
           Options FollowSymLinks
           AllowOverride None
   </Directory>
   <Directory /home/pi/schnapphoto/www/>
           Options Indexes FollowSymLinks MultiViews
           AllowOverride None
           Order allow,deny
           allow from all
   </Directory>

   ScriptAlias /cgi-bin/ /home/pi/schnapphoto/cgi-bin/
   <Directory "/home/pi/schnapphoto/cgi-bin">
           AllowOverride None
           Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
           Order allow,deny
           Allow from all
   </Directory>

   ErrorLog ${APACHE_LOG_DIR}/error.log

   # Possible values include: debug, info, notice, warn, error, crit,
   # alert, emerg.
   LogLevel warn

   CustomLog ${APACHE_LOG_DIR}/access.log combined
   </VirtualHost>

don't forget to reload apache config after you changed it:
`/etc/init.d/apache2 reload`

###8. configure samba:
this is optional, but you may want to edit the sources from a remote system later, so create shares for docroot and cgi-bin.

###9. configure hostap:
In case you plan to use your schnapphoto-system outdoors later, you will need to make the Pi behave as your personal wireless access point, so that you can access it from your smartphone.
There exist many instructions for this, I used this one.
Be aware that not all WiFi-Sticks that are supported by linux are available to run in host mode.
In my personal case, I had to install a rather dubious replacement for the hostapd binary to make my D-LINK DWA 121 work with hostap. Additional instructions can be found here. Use at own risk.

###10. download and install gphoto python bindings
if you're still in super-user-mode, return to normal user privileges:
exit
download and install:
wget https://github.com/enkore/piggyphoto/archive/master.zip -O piggyphoto.zip
unzip piggyphoto.zip
cd piggyphoto-master
vi piggyphtoto/__init__.py
change line 923 from

print(" ",end="")

to

print(" ")

sudo python setup.py install

###11. Download and install schnapphoto:
wget https://github.com/tgoerlich/Schnapphoto/archive/master.zip -O schnapphoto.zip
unzip schnapphoto.zip
now copy the content of the www Directory to the Docroot-Directory of your apache configuration
copy the content of the cgi-bin Directory to the cgi-bin-Directory of your apache configuration

###11. Testing
Now it's time to connect your camera to the Raspi. Switch it on and type:
gphoto2 --abilities
The result should look like this:

Abilities for camera : Nikon DSC D40x (PTP mode)
Serial port support : no USB support : yes Capture choices : : Image Configuration support : yes Delete selected files on camera : yes Delete all files on camera : no File preview (thumbnail) support : yes File upload support : yes

as you can see, gphoto reports that it found the camera and that it supports image capture and remote configuring. Looking good!

Clone this wiki locally