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

About: Systems Administrator and Software Programmer.


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:





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.


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 '' -O<br>chmod 755

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

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/

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: