GATT Client and Java Client

212 views
Skip to first unread message

Matthias Ringwald

unread,
Jun 4, 2014, 4:51:07 PM6/4/14
to btsta...@googlegroups.com
Hi there

There are two new features in BTstack that we didn’t mention here before: GATT Client and Java Client

- The GATT Client allows to query a remote GATT Server e.g. from an LE Peripheral. It is modeled after the Bluetooth Spec and looks similar to the APIs on iOS and Android. There isn’t any documentation yet, but ble/gatt_client.h should get you started and there’s example/libusb/gatt_browser.c that scans for Advertisements and connects to the first device that it finds. It then gets a list of Primary Services and their Characteristics and prints them on the console.

What’s missing for a full LE implementation is the Security Manager for the Central Role. That’s next on our list.

- The Java Client provides access to a BTstack daemon over TCP or Unix Domain Sockets (Android only) without native code or helper libraries. If we ignore Android for a bit, I’d say it’s the only Java BLE implementation out there. Speaking of LE, BTstack currently doesn’t have a way to create an (G)ATT Database dynamically, so it’s not possible to implement an LE Peripheral via the BTstack deamon and therefore via pure Java. All in all, creating this client has been an interesting and fruitful exercise in writing a code generator. It parses the C source and header files (using only regex, of course) and generates Java classes for all Bluetooth commands and events. As the BTstack source code doesn’t list command parameter names, "arg1, arg2, arg3…" is used as a default. I’ve added doxygen/javadoc style comments to provide proper names, but this is incomplete at the moment. Similarly, events are not specified at all, so most events are not available as Java event classes yet (doxygen style comments allow to define them, too)

To try the Java client, you can run ANT in the java folder. It will generate some classes and then compile everything, before running a GATT Client test application. The example assumes that you have BTstack daemon running in TCP mode. You can do this by compiling BTstack with configure/make/make install and then
$ src/BTdaemon —tcp

Aside from Java, it shouldn’t be much effort to adapt the code generator to produce clients for other languages like Python, Ruby, node.js, or …
Let us know, what are you using the new Java client for. Testing comes to my mind first.

Best
Matthias

Mark Flacy

unread,
Sep 5, 2014, 11:05:46 AM9/5/14
to btsta...@googlegroups.com
Greetings,

I've taken the time to re-write your ant/python mix for the java code into a maven MOJO to create the java source from the 'C' code and a pom.xml to use that MOJO to build the java code.  That makes it easier to integrate the BTStack java code into other applications.

The itch that I'm trying to scratch with this work is to use a Polar H7 heart rate monitor to feed a NetBeans application that will display a graph of my heart rate statistics while I'm on my Nordic Track.  This will be running on a Slackware system and BTStack appears to have something that I can use (versus bluez).

I can provide a tarball if you want to look at it.

Matthias Ringwald

unread,
Sep 7, 2014, 4:57:07 AM9/7/14
to btsta...@googlegroups.com
Hi Mark

Welcome and thanks for your first endeavor. I just had to add another type encoding for the returned Command Complete events and it took me a while to find my way around in the generator. I'd love to see yours, sure. While I've been using Java since ages and also use it in my day time job, I deferred switching to maven there as ant was sufficient for the needed tasks (we have checked in copies of used libraries etc..) and I didn't want to spend time on learning/debugging something new :0)

BTstack has been tested for compliance with LE Peripheral, the Central part is still not completed, but it should be able to communicate with the H7 although I didn't try (I should have one somewhere, too. It was kind of the first useful BLE device I found on the market). The current missing issues are: Connection Parameter Updates are not handled yet and the Security Manager won't store generated pairing information. I hope to add the Connection Parameter Updates code soon - I'm currenlty on vacation and what could be more fun than adding some features :)

The Java port has been done as part of a project and might have some rough edges, but I'm happy to address them. I also just got the idea of building a Hue proxy that adds virtual Hue lamps and controls a cheap light strip via BLE. For that, I'll have a good reason to also provide a JavaScript/node.js Binding. Let's see how that plays out. (I already found something similar in Java/Tomcat which I'm familiar, but then, I wouldn't need a JavaScript binding..)

Best
 Matthias

--
You received this message because you are subscribed to the Google Groups "btstack-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.
To post to this group, send email to btsta...@googlegroups.com.
Visit this group at http://groups.google.com/group/btstack-dev.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages