User avatar
Douglas6
Posts: 4562
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

[Guide] Receive files over Bluetooth on the command line

Fri Apr 29, 2016 2:39 am

The GUI package BlueMan provides a convenient front-end for several Bluetooth functions, but it's not clear how to use it to accept files from another Bluetooth device. This guide gives one way of doing that, without BlueMan. We'll want to set up a OBEX push server, so download the software:

Code: Select all

sudo apt-get install obexpushd
We'll need to add the compatibility flag on the Bluetooth daemon, so edit this file:

Code: Select all

sudo nano /etc/systemd/system/dbus-org.bluez.service
Add the ' -C' flag to the end of the 'ExecStart=' line. It should look like this:

Code: Select all

ExecStart=/usr/lib/bluetooth/bluetoothd -C
Save the file and reboot. It's probably best to have a specific directory where received files are placed:

Code: Select all

sudo mkdir /bluetooth
Ok, we'll start by running a command line in a terminal. Enter:

Code: Select all

sudo obexpushd -B -o /bluetooth -n
It should respond with:

Code: Select all

obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
Listening on bluetooth/[00:00:00:00:00:00]:9
If that's not working, and you get:

Code: Select all

obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
BtOBEX_ServerRegister: Address already in use
net_init() failed
it could be because you have BlueMan running, which seems to take the rfcomm channel 9 that obexpushd uses by default. In this case change the channel to 23 like this:

Code: Select all

sudo obexpushd -B23 -o /bluetooth -n
to use channel 23.
Once you get obexpushd running, open a second terminal window. You can verify that the OBEX service is registered with

Code: Select all

 sudo sdptool browse local
. It should list, among others, this.

Code: Select all

Service Name: OBEX Object Push
Service Description: a free OBEX server
Service Provider: obexpushd
Service RecHandle: 0x10005
Service Class ID List:
  "OBEX Object Push" (0x1105)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 23
  "OBEX" (0x0008)
Profile Descriptor List:
  "OBEX Object Push" (0x1105)
    Version: 0x0100
(with channel 23). In that window, while obexpushd is still running, use bluetoothctl to set 'discoverable on'.Now pair from your phone. Pairing MUST be done while obexpushd is running, or the phone wont recognize the service is available. If the phone is already paired, remove it from your phone, use bluetoothctl to remove it from the Pi, and re-pair.

You should now be able to send files from your phone (or other device) to the Pi, they will appear in the /bluetooth directory. Notice that they will be owned by root, so you'll need sudo to access them.
In order to automate the obexpushd command, create this file:

Code: Select all

sudo nano /etc/systemd/system/obexpush.service
Add the following:

Code: Select all

[Unit]
Description=OBEX Push service
After=bluetooth.service
Requires=bluetooth.service

[Service]
ExecStart=/usr/bin/obexpushd -B23 -o /bluetooth -n

[Install]
WantedBy=multi-user.target
Then, set that to autostart with

Code: Select all

sudo systemctl enable obexpush
After a reboot, you should be able to send files from your phone to the Pi

Thiruvasan
Posts: 3
Joined: Thu Aug 31, 2017 6:19 am

Re: [Guide] Receive files over Bluetooth on the command line

Tue Sep 26, 2017 5:22 am

this method is not working any other idea

nouse4anick
Posts: 6
Joined: Mon Jun 19, 2017 2:59 am

Re: [Guide] Receive files over Bluetooth on the command line

Sun Mar 25, 2018 4:24 pm

So I finally got mine working and it receives files perfectly fine.

my question is this though: is there a way I can see the current status of a transfer? is there anything that tells me if something is done?

I want to write a script that will take a picture and send it to another program for processing when it receives a pic.

talha2447
Posts: 2
Joined: Wed Nov 21, 2018 8:55 pm

Re: [Guide] Receive files over Bluetooth on the command line

Thu Nov 22, 2018 1:08 pm

this method is not working for me also.. i had type all command right and they are working fine.. but still i am not able to receive my data or image in Rpi3 from my phone.

User avatar
Douglas6
Posts: 4562
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: [Guide] Receive files over Bluetooth on the command line

Thu Nov 22, 2018 3:43 pm

I just re-tested this on a newly upgraded Raspian Stretch. All steps worked as advertised, and I was able to transfer files from my Android phone. I recommend you unpair and perform the steps again carefully.

DirkS
Posts: 9761
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: [Guide] Receive files over Bluetooth on the command line

Thu Nov 22, 2018 4:51 pm

Douglas6 wrote:
Thu Nov 22, 2018 3:43 pm
I just re-tested this on a newly upgraded Raspian Stretch. All steps worked as advertised, and I was able to transfer files from my Android phone.
Just did this for the first time on a Pi3B and all steps work fine.

Return to “Beginners”