Raspberry Pi - Bluetooth using Bluecove on Raspbian
Introduction
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
Updating 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 3 Jan 2015, 23:23 PM
Tags: Java,Raspberry Pi