Raspberry Pi - Bluetooth using Bluecove on Raspbian

Raspbian LogoIntroduction
I want to cover what exactly people will need to use a bluetooth dongle on a Raspberry Pi and interact with it using Java. I assume, you've already written a program on your Windows PC and it works using Bluetooth on there. (I'm not going to cover the ins and outs of Java programming with Bluetooth.) What I will cover is how to get said program running on the Raspberry Pi.

I also assume you know how to use SSH to your pi via the use of a client such as Bitvise SSH Client.

Requirements
At the time of writing this post, I'm using a Raspberry Pi Model B with the lastest version of Java installed and all updates applied to my Pi.

I have a generic USB Bluetooth adapter that I bought from Maplin. (Chosen because of its small size.)

A 32gb SD card. (You will get by with the minimum reccomended size, I think it's 4gb.)

A power supply.

Installation
You will need to install the bluetooth components on your Raspberry Pi, you can do this by running the following commands.

Update package lists:

Sudo apt-get update

Update packages

Sudo apt-get upgrade

Auto-remove redundant packages

Sudo apt-get autoremove

Install new bluetooth packages

Sudo apt-get install bluetooth bluez-utils blueman

You should now have a bluetooth service installed on your Raspberry Pi, You can check the service using the below command.

/etc/init.d/bluetooth status

And you can scan for bluetooth devices using this command.

hcitool scan

ARM LogoUpdating your application libraries
Chances are, your application uses the Bluecove libaries. An oh look, your application won't run on your Pi because the libraries are not compiled to run on an ARM processor.

1) Now you need to compile your own Jar with the ARM binaries so that it will run on your Raspberry Pi. (Not many sites provide the jar, they make you compile it yourself, so I've done that and provided a zip with the jars pro-compiled. - Scroll down if you're lazy and don't want to compile your own.)

2) You will need to create a folder on your Pi lets call it '/home/pi/temp'.

3) Browse to the new temp folder

cd /home/pi/temp

4) Download the source from the Bluecove SVN using this command:

wget -m -np http://myproject.googlecode.com/svn/myproject/trunk/

A usefull page if you get stuck with this would be this Stack Overflow question page.

5) now you should have all the files in your temp dir. You can list the structure by trying:

ls

6) Compile all the projects within the download. Bluecove, Bluecove EMU and Bluecove GPL. Browse to the project folder using the cd command previously explained and build the project using this command:

ant all

You will find your new jars within a new target folder created within each of the project folders. (You need to compile each project separately.)

Like I said, if you're lazy. Download the Bluecove jar files that I've already compiled on the Pi.

Add the libraries to your application project
You will need to add the libraries to your project in Netbeans/Eclips and rebuild your application then transfer your application jar file to your Pi along with the libs folder which must contain your Bluecove jars and run the application using the following command.

java -jar myjarfilename.jar

You will need to have browsed to the location your application jar file resides.

Done
Your application shoudl now work. Leave a comment if you think anything is missing or you need help.

Edit:

Some people might still find that libbluetooth.so can't be found, running the following command should fix the issue:

sudo apt get install libbluetooth

Published at

Tags: Java,Raspberry Pi

Luke Alderton

Comments

Ike
Hi Luke, This was exteremly helpful, and everything seems to be mostly working. Two questions: Where should the libbluecove_arm.so reside? I've placed it in /usr/lib/ Also, my application doesn't throw any errors when I run it, but the Raspberry Pi doesn't seem to be advertising its service. My BT scanner app recognizes when the RPi is advertising through a command line (hciconfig hci0 leadv) but when I run my Java app I get nothing. Any ideas?
22/04/2015
Luke
Ike, you might need to copy it into your java lib folder however it should work within your applications lib folder.
22/04/2015
Luke
Ike, I've also noticed that on the Raspberry Pi 2, you need to reset the bluetooth service every time you rub your app or it doesn't work correctly, something I'm working on fixing.
22/04/2015
Gaurav
Hey luke thanks for the such great. I followed same steps as mentioned with your precompiled jars and when i run my app it detects bluetooth devices but it seems its not able to detect the beacons. As i needed my app to detect beacons. Also the svn link shared by you doesnt contain the code base.
09/03/2016
Fishwolf
i think that this library doen't work on PI3 right?
18/05/2016
Luke
I can't say I've tested. I do have a Pi3 but have yet to boot it up. :O Let me know what you find if you try it out.
18/05/2016
Staroski
Nice article. I'm working on a OBD2 software using Raspberry Pi 3 Model B. I'll try to compile bluecove for it to see if it works.
31/05/2016
Harshad
Nice article. download source http://myproject.googlecode.com/svn/myproject/trunk/ doesn't work. Can u provide alternative link. Thanks.
14/06/2016
Staroski
In order to compile BlueCove on a Raspberry Pi 3 Model B I had to install the following dependencies: sudo apt-get install bluetooth libbluetooth-dev bluez bluez-cups bluez-obexd Regards.
19/11/2016
James
Thanks!
09/01/2017
Nick
Your article helps me get over the hurdle. Thanks a lot!!!
02/04/2017
Anand
Can you please tell me how to do it in Linux?
07/09/2020
Share with
Tags
Latest Comments
By Mark Gentry on Windows Server 2019 - Change product key does nothing
20 Aug 2021, 03:30 AM
By Cathy on In-Place Upgrade for a Windows Server domain controller
31 Jul 2021, 18:28 PM
By Mr. Greymatter on Raspberry Pi - Running Java app on Raspbian
16 Feb 2021, 07:35 AM
By Mikko Seittenranta on Xamarin Forms multiple instances of same app open
16 Feb 2021, 04:34 AM
By Andrew on Auto/Custom height on Xamarin Forms WebView for Android and iOS
22 Jan 2021, 22:15 PM
By Nick on Raspberry Pi - Running Java app on Raspbian
14 Oct 2020, 19:37 PM
By Ivan on Fixed: Value cannot be null Parameter Name: source
15 Sep 2020, 19:47 PM
By Anand on Raspberry Pi - Bluetooth using Bluecove on Raspbian
7 Sep 2020, 16:53 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development