Wednesday 5 March 2014

Raspberry Pi Photo Backup solution

Raspberry Pi Photo Backup solution

I was looking for a backup solution for my photography trips which was cheap, reliable and which didn’t involve taking my laptop. We do most of our overseas trips with only hand luggage and the laptop is just too great a weight penalty when added to camera equipment and clothes. We do however always take an iPad.

What follows is a step-by-step guide to set up a Raspberry Pi and a portable hard drive as a comprehensive back up solution controlled wirelessly from an Ipad. The extra kit weighs 350g and will fit in a coat pocket or the corner of a camera bag easily.


What you need:
Raspberry Pi                                              £27.80                                      Amazon
Edimax Wi-Fi Dongle EW-7811UN            £7.07                                        Amazon
Cyntech case                                             £5. 95                                       Amazon
SD Card 8Gb                                             £5.20                                        Amazon
The Pi Hut 7 Port Powered Hub                £10.99                                      Amazon
Seagate Slim Portable Drive 500Gb         £44.99                                      Amazon
Remoter VNC                                            £1.99                                       App Store
Total                                                           £103.99

I am assuming you already own an IPad and have an available monitor, keyboard and mouse for installation and setup. You may also have a portable hard drive, which is suitable to use. This of course brings the cost down substantially.

Install Raspbian OS to SD Card

Go to http://www.raspberrypi.org/downloads and follow the instructions to format the card and download and install Noobs. There are instructions for both Windows and MacOs. Make sure you copy the unzipped contents into the root directory of the SD card not into a folder on the card.

Connect mouse, keyboard, wired Ethernet and monitor to the Pi, insert the SD card and connect the power supply.

Your Pi will now boot into NOOBS and should display a list of operating systems that you can choose to install.

If your display remains blank, you should select the correct output mode for your display by pressing one of the following number keys on your keyboard:
1. HDMI mode - this is the default display mode.
2. HDMI safe mode - select this mode if you are using the HDMI connector and cannot see anything on screen when the Pi has booted.
3. Composite PAL mode - select either this mode or composite NTSC mode if you are using the composite RCA video connector.
4. Composite NTSC mode

Choose to install Raspbian.
After installation and a reboot the Raspbian configuration page will launch automatically.



Choose Desktop log-in, tab to <OK> then press Enter

In Advanced Options enable SSH.









Tab to <Finish> Press Enter and Reboot

On first starting the Pi will now boot to the GUI Desktop this has the advantage of being fairly familiar to Windows or Mac users and also auto-mounts external hard drives and SD cards.

It is now worth ensuring that the system is up to date.

Launch LXTerminal. This is a command line interface (CLI), which requires the commands to be typed accurately. If you make a mistake you wont cause any damage, but the command will not execute.
Type:
sudo apt-get update
Then press enter
It will take several minutes to update all the files but eventually the command line will return.
Type:
sudo apt-get upgrade
press enter
You may be asked if you want to continue just press y followed by enter. Wait for the return of the command prompt.
Type:
sudo apt-get dist-upgrade
This may or may not download additional files.

You now have an up to date version of Raspbian on the Pi and are ready to make the modifications necessary to set up an Ad-Hoc network so that the Pi can be controlled from the Ipad without needing a keyboard and mouse. The process up to this point should have taken 30 - 45b minutes.
Type:
sudo shutdown -h now
Press Enter, when the lights stop flashing and only PWR and ACT are solid red disconnect the power supply.


At this stage it is worth making a backup of the SD card. This saves repeating all these steps should the card get corrupted. We will do the same process again at the end.
The easiest way to create a backup is to use “Win32 Disk Imager”. This is a free programme, which creates a disk image of the SD card and stores it on a Windows machine. Once you have created the image it can be written onto a new card and you are ready to go again. You can also make an image of the card with Terminal on the Mac, this requires care and knowledge.


Create an Ad-Hoc Network on the Pi

Plug in the wireless dongle as well as the wired network connection and reboot the Pi.
Start LXTerminal. To edit the interface file type:
sudo nano /etc/network/interfaces

Press enter, edit the file so that it is exactly the same as this:

Auto lo
iface lo inet loopback
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid RPiAdHoc
wireless-mode ad-hoc


Now  press ctrl-x , then y , then enter. this will save the file in its original location with the same name.

To check that this works restart wlan0
Type:
sudo ifup –-force wlan0


Create DHCP server

This allows the Pi to allocate an IP address to the Ipad automatically.
Type:
sudo apt-get install isc-dhcp-server

Press enter, there will be an error message after the package is downloaded when trying to run dhcp server. This is because we need to configure dhcp.
Type:
sudo nano /etc/dhcp/dhcpd.conf

Press enter


This looks a complicated file but you can ignore most of it. # before a line disables the line.

Update the highlighted lines leave the rest of the file as is.

ddns-update-style interim;

default-lease-time 600;
max-lease-time 7200;

authorative;

log-facility local7;

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.5 192.168.1.150;
}

Press ctrl-x, then y , then enter to save the file. Shutdown Pi disconnect wired Ethernet cable.

Restart the Pi

Check network

With the Ipad go to Settings Wi-Fi which will probably be connected to your home network and allow it to discover networks in devices should be RPiAdHoc select this and it should connect. The iPad will show a internet warning, select "Join anyway". We now have a connection between the Pi and the Ipad. We now need to install the software on the Ipad to control the Pi remotely and modify the Pi system to allow this.

Set up VNC on the Pi

Type:
sudo apt-get install tightvncserver

Press enter

You may have to answer “y” during installation. When installation is complete type:

vncserver

Press enter

You need to set a password and confirm. It has to be between 6 and 8 characters. I choose “remoter”. When asked to create a view only password answer “n”.
We now have to make vncserver start automatically at boot up.
Create a new file in init.d.

Type:
sudo nano /etc/init.d/tightvncserver

Press enter

Type:
#!/bin/sh
# /etc/init.d/tightvncserver
VNCUSER='pi'
case "$1" in
    start)
        su $VNCUSER -c '/usr/bin/tightvncserver :1'
        echo "Starting TightVNC Server for $VNCUSER "
        ;;
    stop)
        pkill Xtightvnc
        echo "TightVNC Server stopped"
        ;;
    *)
        echo "Usage: /etc/init.d/tightvncserver {start|stop}"
        exit 1
        ;;
esac
exit 0



Press ctrl-x ,then y , then enter to save the file.
Type:
            sudo chmod 755 /etc/init.d/tightvncserver

Press enter

Type:
            sudo update-rc.d tightvncserver defaults

Press enter.
If you see a "script missing LSB tags and overrides" warning, this can be ignored. All that remains is to install a VNC app on the Ipad and configure it to access the Pi.
Shutdown the Pi and reboot to make sure there are no errors.

Remoter Pro set-up on the Ipad

Purchase and install Remoter VNC or Remoter Pro from the App Store. I prefer Remoter Pro but you can convert Remoter VNC to Pro via in app purchases.
Boot your Pi and open Remoter Pro on the Ipad.
Select add session manually



In Server Type select VNC/ScreenSharing
Add Name: RPiAdHoc
In VNC Hostname: 192.168.1.1
In VNC Port: 5901
Leave VNC Username blank
In VNC Password remoter
Select save in top left hand corner

Leave Remoter Pro go to Ipad, Settings, Wi-Fi wait a few seconds while Ipad searches for networks then select RPiAdHoc in Devices.


You will see message RPiAdHoc is not connected to the internet. Select join anyway.

Back to Remoter select RPiAdHoc and start.

You now have control of the Pi through the Ipad.



Final Touches

Using Ipad control through Remoter left click on the far left icon on the taskbar at the bottom of the screen. When it expands left click on Accessories, when this expands right click on File Manager and select Add to desktop. This will make access to file manager easier from Remoter. Left clicking and right clicking are accomplished by selecting the appropriate icons at the bottom of the remoter screen.




Transferring files

Start the Pi, join the ad-hoc network on the Ipad, start remoter and select VNC to access the Pi.
Plug your hard drive and sd card into the powered USB Hub connected to the Pi.

Open file manager on the Pi desktop.


Click in the top left corner of the file manager window and select resize, a resize icon will appear drag this in order to resize the window.



Click the top left icon again and select move.


Move the window to allow space for a second window. In the file manager window click File and select new window, resize and move if needed.


On the left hand side of the file manager window you will find the hard drive (in this case “Seagate”) and the SD card (in this case EOS_DIGITAL). Select the hard drive for one window and the SD card for the other. Navigate through the directory structure for each disk until you find the photo files on the SD card and the destination directory on the hard drive. If you Click View in the SD card window, then Sort Files and select by file type, this will separate raw files and jpegs so that you can move them to different destinations.


Click on the first file you want to save and then open the keyboard.



At the top of the keyboard select the shift symbol.


Minimise the keyboard then select the last file you want to save. This will highlight all the files. Cancel the shift key on the keyboard. Now with the control method in Remoter on finger select the last of the highlighted files and drag into the destination folder.


Here I have just moved the RAW files. Remember to shutdown the Pi before you unplug the drives. I shutdown by opening a terminal window and typing:
     sudo shutdown –h now
Then press enter.

The whole process including moving some files for practice takes about 90 minutes. 

Once you have completed a test make a back up of the completed set-up using Win32 Disk Imager. I always create an extra SD Card using Disk Imager to write the disk image and carry the spare just in case an SD card gets corrupted.







9 comments:

  1. Interesting solution
    Is the purpose just to have a backup of the images or to also allow easier download from the external drive when you get home.
    If its the first can't you just get an adaptor Ipad-USB and USB card reader and literally copy the images to the Ipad, or does it not have the capacity to store all the images.
    I did this on a Hudl recently, cost 99p for a USB micro - USB adaptor, but then I have 48GB of storage to play with.

    ReplyDelete
    Replies
    1. Thanks for your interest. It's designed as a backup solution for when I'm away on trips. I shoot in RAW and can easily take between 16 - 32 GB of images each day. The IPad just doesn't have the capacity to store that many images.

      Delete
  2. looks like what I have been looking for for a long time... I will try it out. thanks a lot...

    ReplyDelete
  3. What is the transfer speed? How long does it take to copy 4 GB?

    ReplyDelete
    Replies
    1. Sorry for the delay in replying. It runs at USB2 as far as the peripherals are concerned. my test this weekend took six and a half minutes to transfer 4Gb of Camera RAW files. hope this helps

      Delete
  4. Thanks, I was just wondering how get around this problem for this summers holiday. I have just got a pi 2 so I wonder if that has the power to do it without a hub. I'll give it a go when I have a spare afternoon.

    ReplyDelete
  5. Hi, I had to make some tweaks to get this working (was having issues with DHCP.

    1. followed this guide here

    http://www.raspberrypi.org/learning/networking-lessons/lesson-3/README.md

    2. Issued the following commands at the command line and then restarted

    ifconfig wlan0 up
    iwconfig wlan0 mode ad-hoc
    iwconfig wlan0 essid "Pi"
    ifconfig wlan0 192.168.1.1 netmask 255.255.255.0

    3. I also installed exfat support

    sudo apt-get install exfat-fuse

    4. Used VNC Viewer (free iOS app)

    ReplyDelete
  6. I am interested in a way to use a raspberry pi at home, automatically copying files from my CF to an HD when I insert the card. Any ideas? Thank you.

    ReplyDelete
  7. I am interested in a way to use a raspberry pi at home, automatically copying files from my CF to an HD when I insert the card. Any ideas? Thank you.

    ReplyDelete