The Raspberry Pi 3 includes BLE support. I confirmed it works by
sudo hcitool lescan
which returned the MAC and BLE 'complete local name' for neighboring advertisers.
How does one access this programmatically, in Java?
I don't think there is a clear or easy answer available at this time. Bluetooth integration requires native components that are not part of a standard JDK.
The most common library used for using Bluetooth with Java on Linux is BlueCove. BlueCove provides extra native libraries for working with Bluetooth on linux: BlueCove-GPL or BlueCove-bluez(experimental). However, you will likely need to compile one of these yourself for use on your RPi. Methods for doing do will be dependent on your distribution and will require some significant knowledge of linux, compiling native code, etc. A quick google search shows some working examples of this for previous RPi versions. It's unclear if it will work with the BLE on RPi 3 though.
Another might be to try using "Camel Bluetooth Component", which is wrapper over Bluecove and expects libbluetooth-dev and blueman to be installed. But again, not clear if it will work with RPi 3.
If unable to get a true integration working, another option might be to simply make external Process calls out from Java to the command line Bluetooth utilities that you know already work. It depends on your use-case if this an option, but I suspect could be sufficient for many BLE specific use cases.
To use BLE on Raspberry Pi 3 you have to update bluez (the bluetooth core in Raspbian linux) then use the bluez D-Bus interface to interact with it.
I'm looking for writing my own java lib, but it's very difficult because there are few documentation about D-Bus in java and about bluez.
For bluez there are only the sample code in the last distribution.
For now i have write a simple script that update the bluez version to the latest: https://gist.github.com/tongo/94338cebf4e6367d353439bca8d0a376
I have also found a blog post that talk about d-bus,java and bluez: http://smartspacestuff.blogspot.it/2016/02/i-got-figurin-out-dbus-bluez.html
It was useful, but not very clear for me.
I hope this can help.
If you found other documentation post it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With