Introduction: Customize Behaviour of Bluetooth OBEX Push Service Running on Raspberry Pi

Picture of Customize Behaviour of Bluetooth OBEX Push Service Running on Raspberry Pi

Introduction

This instructable built upon the following instructables:



1. Turn the Raspberry Pi into a Bluetooth Device
2. Send a copy of your photos and videos in your Android Phone to Raspberry Pi using Bluetooth


Both my wife and I individually own an Android Phone and we share the Raspberry Pi. We want to transfer photos from our individual Android Phone to separate directories according to media types. In addition, within each media type directory, we want to sort photos and videos into further sub-directories according to individual phones. The following is an illustration of the directory structure that we need:

/home/pi/media_fr_phone/videos/his

/home/pi/media_fr_phone/videos/hers

/home/pi/media_fr_phone/photos/his

/home/pi/media_fr_phone/photos/hers

Implementing this type of sorting process by following my earlier instructable results in an inconvenient work flow.Therefore there is a need to customize the behaviour of OBEX Push Service so that we can achieve our objectives with ease.

I learned from the manual of obexpushd that the OBEX Push Service can be customized through the use of a programming script.

Scope

This instructable will show:



• A script that implements the type of sorting process that I require.
• Configure the script to suit your needs
• How to make OBEX PUSH Service use the script.
• How to test the above is working


Target Readers

This instructable will mostly benefit Linux users, especially Debian and its derivatives like Raspberry Pi running Raspbian OS.

System Environment

A notebook PC with the following specification:



• Intel® Core™2 Duo Processor
• Debian 7.4
• Bluetooth Radio Built-in


Raspberry Pi with the following specification:



• Model B
• Debian 7.6
• Bluetooth Radio USB Adaptor
• Mains-Powered USB Hub

Step 1: Turn the Raspberry Pi Into a Bluetooth Device

Complete the steps in "Turn the Raspberry Pi into a Bluetooth Device" instructable.

Step 2: Install Bluetooth Data Link Services, Middleware and OBEX Push Service

Step 3: Discover Android Phones

On Android Phones:

Swipe down from top of screen with two fingers

Tap on Bluetooth Button

Tap on button that says "Only visible to paired devices" until it changes to show "Visible to all nearby Bleetooth devices"

________

On Raspberry Pi:

Open a terminal emulator

Discover Bluetooth-enabled Android Phone, type the following:

hcitool scan
Scanning ...
F8:E0:79:31:7F:C0 PHONE1
G3:F3:22:45:5T:C2 PHONE2

Note down the above details and determine the owner of the phones listed above

Step 4: Download and Install the Python Script

The script can be written in other language. I chose to write a python script.

Open your favourite terminal emulator lile LXTerminal

Install wget:

sudo apt-get update
sudo apt-get install wget

Download the script and make it executable:

mkdir /home/pi/obex_script<br>cd /home/pi/obex_script<br>wget 'https://www.instructables.com/files/orig/FGM/7AYH/I1VZC4UL/FGM7AYHI1VZC4UL.py' -O obex_sort_media.py<br>chmod 755 obex_sort_media.py

Open and read the script in your favourite text editor

Step 5: Configure the Python Script

Get the bluetooth address of the 2 phones

hcitool scan
F8:E0:79:31:7F:C1
F8:E0:79:31:7F:C0

The first bluetooth address belong to my partner and the second one belong to me

Open the Python Script using your favourite text editor

Under the section called "Configurations/Settings", I change the setting to the following:

BASE_FOLDER = 'media_fr_phone'<br>
VIDEO_PATH = 'videos'<br>
IMAGE_PATH = 'photos'
<p>bt_db = {</p><p>            'F8:E0:79:31:7F:C1':'hers',</p><p>            'F8:E0:79:31:7F:C0':'his',</p><p>        }</p><p>Save the file</p>

Step 6: Run the OBEX Push Service

Check whether any OBEX Push Service is running

$ps aux | grep obexpushd

Kill any running OBEX Push Service

Run OBEX Push Service

obexpushd -B -n -s /home/pi/obex_script/obex_sort_media.py

Step 7: Transfer Photos From Two Phone to Raspberry Pi

To test if your installation works as expected, you need two Android phones.

On each Android Phone:

Transfer Photo from first Android Phone to Raspberry Pi

Transfer Photo from second Android Phone to Raspberry Pi

On Rapsberry Pi:

Check that the photos are stored in the correct directories:

/home/pi/media_fr_phone/photos/his/picture_fr_his_phone.jpg

/home/pi/media_fr_phone/photos/hers/picture_fr_her_phone.jpg

Comments

seamster (author)2014-11-04

This is a nice addition to the latest series of tutorials from you. Great work!