• First Steps
  • General
  • Projects
Facebook Twitter YouTube
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
  • Hardware & GPIO
  • Sensors & Components
  • Scale
  • Cases
  • Fingerprint
  • Gas Sensor
  • Heartbeat
  • German
  • French
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
Home»Software»Raspberry Pi Bluetooth Data Transfer to the Smartphone

Raspberry Pi Bluetooth Data Transfer to the Smartphone

Facebook Twitter LinkedIn Tumblr Email Reddit
Raspberry Pi Bluetooth Datentransfer
Share
Facebook Twitter LinkedIn Email Tumblr Reddit Telegram WhatsApp

In addition to some wireless connections such as 433Mhz, infrared and NFC, Bluetooth is probably the most common and popular mode of data transmission between smartphones, which is why the Raspberry Pi Bluetooth data transfer is interesting. Meanwhile, pretty much all devices support Bluetooth and can not only be paired with it but of course, you can also transfer data, which is interesting for projects such as a Car PC.

This tutorial will show you how to exchange files between Raspberry Pi and a Bluetooth-enabled mobile phone/smartphone.

 

Required Hardware Parts

In this tutorial, I used the following hardware parts:

  • Raspberry Pi Model (Raspbian OS)
  • if neccessary: USB Bluetooth Adapter
  • Bluetooth enabled mobile phone (Android, iOS, etc.)

The Bluetooth adapter can have a significant impact on the range. Cheap devices often do not recognize the connection after a few meters or obstacles, whereas higher-quality dongles also work up to a distance of 30 meters (outdoors).

 

Setting up the Software

First, some packages have to be installed:

sudo apt-get install bluez-utils libopenobex1 obexftp obexpushd --yes

 

After the USB Bluetooth dongle is connected, we check if it has been recognized correctly:

lsusb | grep Bluetooth

If a device has been detected, it will look like this:

raspberry pi bluetooth console

 

Now we check if the Bluetooth service has already been started (it is automatically loaded every time you restart).

sudo service bluetooth status
If the service is not running, you can also restart it with: sudo service bluetooth restart

 

For the device to be connected, it (smart phone) must be searched for. It starts a scan, which should find all devices in the immediate vicinity.

hcitool scan

The mobile phone should be found directly. If not, wait a few seconds as the last result is cached. If it’s detected, it will look like this:

pi@raspberrypi ~ $ hcitool scan
Scanning ...
        C4:42:02:41:B2:06       SM-G901F

This address of the device is important and will continuously be needed. In the following step, it must be changed according to your device address.

In order to connect the Pi and your mobile phone, this address must be specified (adjust it!):

sudo bluez-simple-agent hci0 C4:42:02:41:B2:06 yes

Then you will be asked for a code which you also have to enter on the mobile phone (for example 1234).
After that, the devices should be connected.

 

 

Send Files with the Raspberry Pi Bluetooth Module

Files can be sent on different channels. To find out which OBEX channel your smartphone uses, you can use the following command:

browse C4:42:02:41:B2:06 | egrep "Service Name:|Channel:"

Now you have to see which channel is under “OBEX Object Push”. For me, that is Channel 12.

To transfer a file (here ~/TEST.txt) you have to specify the following command (do not forget to change it):

obexftp --nopath --noconn --uuid none --bluetooth C4:42:02:41:B2:06 --channel 12 -p ~/TEST.txt

Subsequently, a request will pop up on the smartphone, which must be confirmed.

A number of other examples of obexftp can be found here.

 

 

Receive Files using Raspberry Pi Bluetooth

To receive files, we start an FTP server on the Raspberry Pi, which is waiting for files. With screen, the server can also be run in the background.

sudo obexpushd -B -n

Now you can select the file to be sent on the smartphone and send it to the connected Pi. Of course, depending on the size, it can take a bit. The file is created in the directory from which the server was started.

 

Finally, it should be said that the connected devices remain stored and no reconnecting is necessary, as long as both devices (Raspberry Pi Bluetooth Module and a terminal device such as a smartphone) are within reach of each other.

CarPC data transfer FTP ftp server musik abspielen obex
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleRaspberry Pi Zero – Establishing an Ethernet connection (ENC28J60)
Next Article ESP8266: Arduino IDE für den ESP32 installieren – Tutorial

Related Posts

Control all GPIOs with the Raspberry Pi REST API via Python

Using TensorFlow Lite with Google Coral TPU on Raspberry Pi 4

Raspberry Pi Samba Server: Share Files in the Local Network

Build Live Text Recognition with the Raspberry Pi (OCR)

7 Comments

  1. Juan Carlos Fischer on 3. December 2019 18:28

    Hello:
    This is what I got:

    pi@raspberrypi:~ $ sudo apt-get install bluez-utils libopenobex1 obexftp obexpushd –yes
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package bluez-utils is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    bluez

    Package libopenobex1 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘bluez-utils’ has no installation candidate
    E: Package ‘libopenobex1’ has no installation candidate

    My data:
    Static hostname: raspberrypi
    Icon name: computer
    Machine ID:
    Boot ID:
    Operating System: Raspbian GNU/Linux 10 (buster)
    Kernel: Linux 4.19.75-v7+
    Architecture: arm

    Reply
    • Timon Yoder on 3. December 2019 18:47

      Try
      sudo apt-get update
      then
      sudo apt-get upgrade

      Reply
  2. BertKorthof on 5. December 2019 13:52

    Try
    sudo apt-get update
    then
    sudo apt-get upgrade
    NO effect, same problem as Timon Yoder

    Reply
  3. J0hn on 4. July 2020 23:50

    Transfer from LT to RPi, where does it save?

    Reply
  4. Tom on 7. July 2020 18:57

    In this example, it will be in whatever folder you were running the command from. Other examples on the web tell you to create a folder, and then specify the file transfer location using the -o option. Here’s what I was using on my old setup. sudo obexpushd -B -o /home/pi/Documents/file_transfer -n

    Reply
  5. Raj on 23. June 2021 4:20

    How can I transfer data , movie, songs etc from my Android phone to raspberry Pi 4

    Reply
  6. ruz,man on 12. January 2024 7:15

    excellent postie

    Reply

Leave A Reply Cancel Reply

Let Raspberry Pi Robots Follow Their Own Voice (Part 5)

Home Assistant on Raspberry Pi – Getting Started

How to connect and control a Raspberry Pi WS2801 RGB LED Strip

Programming Raspberry Pi Robot: Making it Follow the Lines (Part 2)

How to setup a Raspberry Pi Security Camera Livestream

Raspberry Pi Web Server Installation Part 6 – DNS Server via No-IP

Subscribe to Blog
Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!
Subscribe

Thank you!

We will contact you soon.

Tutorials for Raspberry Pi
Facebook Twitter YouTube
  • Contact & Disclaimer

Type above and press Enter to search. Press Esc to cancel.