Saturday, February 09, 2013

Automatic remote sync BB10 Device

[ Crossposted from अनकही ]
In my previous post, I mentioned that the various sharing options in BlackBerry 10 OS make life easier. I this post, I am going to describe how to use the network sharing option to remotely transfer media from your BlackBerry Z10 and store it on an external drive, that too without using desktop software.

I have a jumbo external drive connected to Raspberry Pi which makes a home file share. It runs miniDLNA and Simple Samba to share files to all devices on the network. It is eunning official Raspbian image. The instructions below allow my Raspberry Pi ( or any Linux computer) to periodically download photos and videos from my Z10 and store on the hard disk, I do not need to connect my phone via USB.

1. In BB10 settings, go to "Storage and Access" and enable "Access using Wi-Fi". Also set the "Wi-Fi storage password" by clicking button just below it. The very next button on Z10 tells you the Z10's device name on your network and username. Please make a note of these.

2. I have a wireless LAN router which provides networking to all devices, including Z10. You need to have either a static IP assigned to your BB10 device or the router should assign a name using DNS. Please refer to your network router manual for this. The idea is that your BB10 device should always have the same IP address or name assigned to it and should be reachable with this name from Linux computer.

3. Create mount point in Linux by running command "sudo mkdir /media/bb10". Also have CIFS UTILS installed by running "sudo apt-get install cifs-utils".

4. Create a file /home/pi/SCRIPTS/download_z10_media.sh containing the following code:

#!/bin/bash -l

Z10_DEVICE="192.168.0.ab" # IP address or network name of your BB10 device, you set in step #2
Z10_USERNAME="BlackBerry"
Z10_PASSWORD="PASSWORD" # The Wi-Fi storage password you set in step #1
Z10_MOUNTPOINT="/media/bb10"

IMG_DEST="/media/mybook/11_PHOTOS" # Directory to store Photos
VID_DEST="/media/mybook/12_VIDEOS" # Directory to store Videos

copy_dir_contents()
{
dr="${Z10_MOUNTPOINT}/$1"
for src in `find $dr \( -name '*.jpg' -o -name '*.mp4' \)`
do
fl=`basename $src`
dt=`stat --printf="%y" $src |awk '{ print $1}'`
if echo $fl| grep -q jpg
then
tgt="$IMG_DEST/$dt/$fl"
loc=`dirname $tgt`
if [ ! -e $tgt ]
then
mkdir -p $loc
cmd="cp $src $tgt"
echo $cmd >>$LOG_FILE
$cmd
else
echo "exists: $tgt"
fi
elif echo $fl| grep -q mp4
then
tgt="$VID_DEST/$dt/$fl"
loc=`dirname $tgt`
if [ ! -e $tgt ]
then
mkdir -p $loc
cmd="cp $src $tgt"
echo $cmd >>$LOG_FILE
$cmd
else
echo "exists: $tgt"
fi
fi
done
}

SCRIPTNAME="$0"
LOG_FILE=`echo $SCRIPTNAME |sed -e 's/sh$/log/1'`
LOCK_FILE=`echo $SCRIPTNAME |sed -e 's/sh$/lock/1'`

echo -n "Starting " >> $LOG_FILE
date >> $LOG_FILE
# if lock file exists, no action
if [ -e "$LOCK_FILE" ]
then
echo "another instance running" >> $LOG_FILE
exit 1
fi
echo "creating lock" >> $LOG_FILE
touch "$LOCK_FILE"

# create mount point
mkdir -p $Z10_MOUNTPOINT

# Internal memory
/sbin/mount.cifs //$Z10_DEVICE/media $Z10_MOUNTPOINT --verbose -o user=$Z10_USERNAME,pass=$Z10_PASSWORD 2>> $LOG_FILE
copy_dir_contents camera
copy_dir_contents photos
copy_dir_contents videos
umount $Z10_MOUNTPOINT

# SD Card
/sbin/mount.cifs //$Z10_DEVICE/removable_SDCARD $Z10_MOUNTPOINT --verbose -o user=$Z10_USERNAME,pass=$Z10_PASSWORD 2>> $LOG_FILE
copy_dir_contents camera
copy_dir_contents photos
copy_dir_contents videos
umount $Z10_MOUNTPOINT

date >> $LOG_FILE
echo "removing lock" >> $LOG_FILE
rm "$LOCK_FILE"

Test the above script by running it from shell.

5. Once the script works from shell, you would want it to run periodically. And this should run with root permission because of the mount command. To do this, add following line in roots cron, by running sudo crontab -e
0,30 * * * * /home/pi/SCRIPTS/download_z10_media.sh
This configures it to run every 30 minutes.

Sunday, July 17, 2011

My workstation

[ Crossposted from अनकही ]
This is my small workstation.

Sent from my BlackBerry device on the Rogers Wireless Network

Canada Day Celebrations

[ Crossposted from अनकही ]