Page 1 of 1

[Guide] Receive files over Bluetooth on the command line

Posted: Fri Apr 29, 2016 2:39 am
by Douglas6
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

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

Posted: Tue Sep 26, 2017 5:22 am
by Thiruvasan
this method is not working any other idea

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

Posted: Sun Mar 25, 2018 4:24 pm
by nouse4anick
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.

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

Posted: Thu Nov 22, 2018 1:08 pm
by talha2447
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.

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

Posted: Thu Nov 22, 2018 3:43 pm
by Douglas6
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.

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

Posted: Thu Nov 22, 2018 4:51 pm
by DirkS
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.

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

Posted: Thu Jun 13, 2019 9:52 pm
by maranhao
Doug, great walk through of the process. Everything works for me with the exception of the autostart. After creating the file (by copy and pasting your text) I ran "sudo systemctl enable obexpush", rebooted my Pi and then checked to verify it was working by running "sudo sdptool browse local" and it does not show up. If I manually run "sudo obexpushd -B23 -o /bluetooth -n" and then run sdptool it appears to be running.

Thoughts? Thanks in advance!

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

Posted: Thu Jun 13, 2019 10:34 pm
by maranhao
Thanks for the helpful tutorial Douglas. Everything worked for me with the exception of the autostart. After executing "sudo systemctl enable obexpush" and rebooting I ran "sudo sdptool browse local" and didn't find an instance of obexpush running.

Thoughts? Any help is much appreciated.

Thanks!

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

Posted: Thu Jun 13, 2019 11:23 pm
by Douglas6
What are the results of

Code: Select all

systemctl status obexpush
?

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

Posted: Fri Jun 14, 2019 4:02 pm
by maranhao
● obexpush.service - OBEX Push service
Loaded: loaded (/etc/systemd/system/obexpush.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2019-06-13 18:08:16 CDT; 16h ago
Process: 355 ExecStart=/usr/bin/obexpushd -B23 -o /bluetooth -n (code=exited, status=0/SUCCESS)
Main PID: 355 (code=exited, status=0/SUCCESS)

Jun 13 18:08:15 raspberrypi systemd[1]: Started OBEX Push service.
Jun 13 18:08:15 raspberrypi obexpushd[355]: obexpushd 0.11.2 Copyright (C) 2006-2010 Hendrik Sattler
Jun 13 18:08:15 raspberrypi obexpushd[355]: This software comes with ABSOLUTELY NO WARRANTY.
Jun 13 18:08:15 raspberrypi obexpushd[355]: This is free software, and you are welcome to redistribute it
Jun 13 18:08:15 raspberrypi obexpushd[355]: under certain conditions.
Jun 13 18:08:15 raspberrypi obexpushd[355]: Listening on bluetooth/[00:00:00:00:00:00]:23
Jun 13 18:08:15 raspberrypi obexpushd[355]: SDP session setup failed, disabling bluetooth
Jun 13 18:08:15 raspberrypi obexpushd[355]: net_init() failed

EDIT: So I get the same output when I run obexpushd not as super user. Its odd to me though because the .service file should be running as root as I didn't list a user or group...

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

Posted: Sun Jun 16, 2019 9:50 pm
by Douglas6
Not sure what's wrong. Are you sure you have the -C compatibility flag when starting bluetoothd?

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

Posted: Sun Jun 16, 2019 10:08 pm
by maranhao
Yes, uppercase C. My full /etc/systemd/system/dbus-org.bluez.service file is as below.

Code: Select all

[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd -C
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1
ProtectHome=true
ProtectSystem=full

[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
I noticed I get the same output when I run obexpushd not as super user. Its odd to me though because the .service file should be running as root as I didn't list a user or group...

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

Posted: Mon Jun 17, 2019 6:49 pm
by maranhao
So the output of

Code: Select all

systemctl status obexpush
that demonstrates the session failed to setup is identical to what I see when I terminate the obexpush service by pressing Ctrl+C. It is as if the autostart service file kills the process upon completion of the autostart. Does that make sense?

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

Posted: Mon Jul 29, 2019 10:11 am
by Mark_The_O
I am facing the same problem with the autostart service. Have you made any progress? I also feel it is doing the service then terminating the obexpush service similar to how we can terminate it by pressing Ctrl-C when manually starting the service in a terminal.
maranhao wrote: So the output of

Code: Select all

systemctl status obexpush
that demonstrates the session failed to setup is identical to what I see when I terminate the obexpush service by pressing Ctrl+C. It is as if the autostart service file kills the process upon completion of the autostart. Does that make sense?