User Tools

Site Tools


Site Tools

Raspberry Pi related projects


Time-laps of Computer installation

I used sftp to store data in this configuration. After few weeks of usage, it turns to be a bad idea (everything “freeze” when the server is not responding). Prefer NFS or other remote storage system.

Here is a cheap way to make a time-laps of a new supercomputer installation. We have here 1 central computer (saving photos) and 4 raspberry pi with camera module.

               +------------+------------+------------+------------+
               |   10.0.0.2 |   10.0.0.3 |   10.0.0.4 |   10.0.0.5 |
          PC --+          Pi+Cam       Pi+Cam       Pi+Cam       Pi+Cam
           10.0.0.1

Each raspberry will mount a repertory on PC (10.0.0.1) using the simple sshfs at boot, and write each capture on it (to save SD cards from intensive write). First install the PC (I used a Xubuntu 14.04) and create directories where photos will be written :

mkdir /home/pcuser/photos
mkdir /home/pcuser/photos/cam2
mkdir /home/pcuser/photos/cam3
mkdir /home/pcuser/photos/cam4
mkdir /home/pcuser/photos/cam5

Now the Pi. We will setup a single pi, and duplicate it's SD card on others.
Note : to write image to sdcard, use (same in reverse order for backup) :

dd if=/path/to/downloaded.img of=/dev/devicenode bs=1M

Default raspbian image does not have sshfs installed, so you will need to download few packages on a raspberry :

sudo apt-get install sshfs

You will also need to configure network and use raspi-config to expand file system. (lot of documentation on the web). Use also this tool to activate camera module. To get more informations on how to setup the camera module : http://www.linuxuser.co.uk/tutorials/pi-camera-quick-installation-guide
To configure date (assuming you can reach web from each pi) :

sudo dpkg-reconfigure tzdata
reboot

Make the directory were we will mount :

mkdir /home/pi/out

Now, we need to activate non pass-phrase ssh keys to ssh connect from pi to PC. Note that it is a security risk, I assume you now these risks. Generate a key using ssh-keygen (do not enter anything, just press enter for each question):

ssh-keygen -t dsa

Now, copy the content of /home/pi/.ssh/id_dsa.pub of each pi in /home/pcuser/.ssh/authorized_keys to let pi connect to PC without using a password. Try connecting to check.
OK, we need to setup a script that will mount this directory at startup using the user pi and not root (sshfs does not support multiusers). Create a new file in /etc/init.d called “sshfsmount” and add this :

#! /bin/sh
# /etc/init.d/sshfsmount
#

# Some things that run always
touch /var/lock/sshfsmount

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting script sshfsmount "
    su -l pi -c "sshfs pcuser@10.0.0.1:/home/pcuser/photos/cam2 /home/pi/out
    ;;
  stop)
    echo "Stopping script sshfsmount"
    fusermount -u /home/pi/out
    ;;
  *)
    echo "Usage: /etc/init.d/sshfsmount {start|stop}"
    exit 1
    ;;
esac

exit 0

(more informations here : http://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian)
Now activate it at startup and reboot :

sudo update-rc.d sshfsmount defaults
sudo reboot

Login and check if all goes well :

df
Filesystem                                  1K-blocks    Used Available Use% Mounted on
rootfs                                       14988412 2159696  12174504  16% /
/dev/root                                    14988412 2159696  12174504  16% /
devtmpfs                                       187320       0    187320   0% /dev
tmpfs                                           38300     208     38092   1% /run
tmpfs                                            5120       0      5120   0% /run/lock
tmpfs                                           76580       0     76580   0% /run/shm
/dev/mmcblk0p1                                  57288    9656     47632  17% /boot
pcuser@10.0.0.1:/home/pcuser/photos/cam2 132517248   92928 125669712   1% /home/pi/out

Last thing is to test camera module and set captures in crontab. Try a capture using (You have here 2 formats of files, use the one you want, note that this is absolutely not optimized):

file=$(date +%s).png
fileof=$(date +%Y%m%d%H%M%S).png
raspistill -o out/$file
cp out/$file out/$fileof

If it goes well, create the script /home/pi/capture :

#!/bin/bash
file=$(date +%s).png
fileof=$(date +%Y%m%d%H%M%S).png
raspistill -o out/$file
cp out/$file out/$fileof

Make it executable with chmod +x and add it in the crontab of user pi using “crontab -e” (here each 15s):

* * * * * /home/pi/capture
* * * * * sleep 15; /home/pi/capture
* * * * * sleep 30; /home/pi/capture
* * * * * sleep 45; /home/pi/capture

Reboot, this should be good now, check if photos are present on PC in /home/pcuser/photos/cam2. Power of the pi, save the SD card into an image to replicate this image on other pi. Now boot each pi separately, and edit the sshfsmount script to set the correct /home/pcuser/photos/cam? directory and edit network configuration to set the correct ip.
Done. Cheap and easy.