Transfer MP3 Songs in Raspberry Pi to Android Phone Using Bluetooth
by mirza irwan osman in Circuits > Raspberry Pi
19618 Views, 18 Favorites, 0 Comments
Transfer MP3 Songs in Raspberry Pi to Android Phone Using Bluetooth
Introduction
Chances are you have lots of mp3 files stuck in a PC like I do. I wanted to listen to the songs when I am out. So that's my motivation for making this instructable.
Scope
This instructable will show:
- How to install Bluetooth in the Raspberry Pi
- How to make Android Phone become a Bluetooth File Transfer Profile (FTP) server
- How to make Raspberry Pi become a Bluetooth File Transfer Profile (FTP) client
- How to transfer mp3 file to the Android Phone using a Bluetooth File Transfer Profile (FTP) client in Raspberry Pi
- How to test successful transfer
This instructable will NOT show how to operate MP3 Player in Android
Target Readers
This instructable will mostly benefit Linux users, especially Debian and its derivatives like Raspberry Pi running Raspbian OS.
System Environment
Raspberry Pi with the following specification:
- Model B
- Debian 7.6
- Bluetooth Radio USB Adaptor
- Mains-Powered USB Hub
Android Phone with the following specification:
- Android Kitkat
- Bluetooth Interface
Install Bluetooth in the Raspberry Pi
Follow all the steps in my "Install Bluetooth in Linux System" instructable.
Make Android Phone Become a Bluetooth File Transfer Profile (FTP) Server
Follow all the steps in my "Make Android Phone become a Bluetooth File Transfer Profile (FTP) Server" instructable.
Install Bluetooth File Transfer Profile (FTP) Client in Raspberry Pi
Open Terminal Emulator like LXTerminal.
Install Bluetooth FTP client program
sudo apt-get update
sudo apt-get install obexftp
sudo apt-cache show obexftp
Output of terminal emulator
Package: obexftp
Version: 0.23-1.1+rpi1
Architecture: armhf
Maintainer: Hendrik Sattler
Installed-Size: 82
Depends: libbfb0, libbluetooth3 (>= 4.91), libc6 (>= 2.13-28), libmulticobex1, libobexftp0, libopenobex1
Conflicts: libobexftp1
Provides: flexmem
Homepage: http://triq.net/obex
Priority: optional
Section: comm
Filename: pool/main/o/obexftp/obexftp_0.23-1.1+rpi1_armhf.deb
Size: 29922
SHA256: 5c7c496ce977179265e25841048cc4fea82eceabc3c62dbfa0c4def7cbc7e08a
SHA1: 152048a8188394157cf1fce2d19b1bb663231923
MD5sum: 21cf4cd13a7b917973c19f2130c7b712
Description: file transfer utility for devices that use the OBEX protocol
OBEX, the OBject EXchange protocol, can best be described as binary HTTP.
OBEX is optimized for ad-hoc links and can be used to exchange
all kind of objects like files, pictures, calendar entries (vCal)
and business cards (vCard) over bluetooth, IrDA, USB and serial cable
links.
.
This is the command line front-end that fully uses the capabilities of
libobexftp.
Find the Bluetooth Address of the Android Phone
In Raspberry Pi
Open terminal emulator like LXTerminal
Scan for nearby bluetooth device:
hcitool -i hci0 scan
Output of terminal emulator
Scanning ...
Z8:E0:79:31:7F:C1 JEBAT-MOTO
Remember the Bluetooth address Z8:E0:79:31:7F:C1
Run a Pairing Agent
In Raspberry Pi
Open terminal emulator like LXTerminal
Run an pairing agent that whose function is to receive a pairing request
bluez-simple-agent
Output of terminal emulator
Agent registered
Send MP3 File in Raspberry Pi to Android Phone
In Raspberry Pi
Open terminal emulator like LXTerminal.
Change directory to where the song is stored.
cd /home/pi/my_songs
Recall the bluetooth address (eg. Z8:E0:79:31:7F:C1) of the Android Phone found in the previous step because the address is one of the input to the next step.
Send file using Bluetooth File Transfer Profile (FTP) client:
obexftp -b Z8:E0:79:31:7F:C1 -c Music -p song.mp3
In Android Phone
Look at the Android Phone for any prompts
Android Phone may issue a "Bluetooth Pairing Request" event
Swipe down from top with one finger to display status screen
Tap on "Bluetooth Pairing Request" event
Android Phone may display a "Bluetooth Pairing Request" dialog box
Enter a pin for pairing: 1234
Tap on done button
In Raspberry Pi
Look at the terminal emulator window that is running bluez-simple-agent program
The bluez-simple-agent program may prompt you to enter pairing pin
Output of terminal Emulator
RequestPinCode (/org/bluez/2044/hci0/dev_F8_E0_79_31_7F_C0)
Enter PIN Code:
Enter the same pin as in Android: 1234
Look at the terminal emulator that you had executed the program "obexftp -b Z8:E0:79:31:7F:C1 -c Music -p song.mp3"
Observe the log messages being printed
Output of terminal emulator running "obexftp -b Z8:E0:79:31:7F:C1 -c Music -p song.mp3"
Browsing F8:E0:79:31:7F:C0 ...
Connecting..\done
Tried to connect for 1931ms
Sending "Music"...|done
Sending "song.mp3"...\done
Disconnecting..|done
The following line in the output indicates successful transfer:
'Sending "song.mp3"...\done
The following lines in the output indicates failed transfer:
Sending "song.mp3"... failed: song.mp3
The operation failed with return code 1
Status
So the above transfer was a success.
Test That Android Phone Has Actually Receive the MP3 File
In Android Phone
Open MP3 player. (I highly recommend "Rocket Player")
Make the MP3 player rescan the device. (This rescan function is available in Rocket Player but I could not find such a function in Google Music Player)
Look for the song
Status
The transfer of MP3 file is successful if you located the song.