How to enable BLE notifications?
응답
17. 11. 24 오후 1:52

I'm connecting via an Android Java App to my XDK. The connection works and I can start the data stream (SendAccelerometerDataOverBle). But I need to turn on notifications for which I need a descriptor from an UUID. Which one do I need to use here?

BluetoothGattService Service = mBluetoothGatt.getService(UUID.fromString("b9e875c0-1cfa-11e6-b797-0002a5d5c51b"));
if (Service == null) {
    Log.e(TAG, "service not found!");
}
BluetoothGattCharacteristic charac = Service
        .getCharacteristic(UUID.fromString("0c68d100-266f-11e6-b388-0002a5d5c51b"));
if (charac == null) {
    Log.e(TAG, "char not found!");
}

mBluetoothGatt.setCharacteristicNotification(charac, true);

BluetoothGattDescriptor descriptor = charac.getDescriptor(UUID.fromString("0c68d100-266f-11e6-b388-0002a5d5c51b"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

Log.i(TAG, "Notifications should be enabled");

When I try the standard characteristics UUID my descriptor is null.

0 (0 투표)
RE: How to enable BLE notifications?
응답
17. 11. 24 오후 2:43 as a reply to Franz Kroll.

Hello Franz,

I can verify that you got the correct service, I am not so ure about the characteristic, though.

The characteristic UUID that you inserted seems to be the one for writing.

The characteristic UUID that allows to receive data via Notifiy is

1ED9E2C0-266F-11E6-850B-0002A5D5C51B

If changing the UUID does not solve the issue, I would recommend to programmatically list all Characteristics of the Service by using the function getCharacteristics() of the BluetoothGattService instance.

I would assume that, by using this way, you already have characteristics allocated, so a null pointer should be less of a problem.

I proposed a similar approach in this thread here, where a user has an issue trying to use a characteristic's Notify option. He is programming in C# instead of Android, though. The idea is the same.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo

0 (0 투표)
RE: How to enable BLE notifications?
응답
17. 11. 24 오후 5:26 as a reply to Franjo Stjepandic.

I already tried that. It gives me the UUID you proposed:

1ED9E2C0-266F-11E6-850B-0002A5D5C51B

But my descriptor is still null and I can't activate notifications on the XDK.

 

I also tried the BLE Scanner App, which receives the data just fine. So the error must be somewhere in my code.

Edit: Works now, still had some UUIDs switched around ;).

Is it normal, that the Z value of the accleration is always around 1000?

Where can I set the sample rate in the example?

0 (0 투표)
RE: How to enable BLE notifications?
응답
17. 11. 25 오후 8:55 as a reply to Franz Kroll.

Hello Franz, how are you.
 

I think Franjo posted the hints to fix your issue, let me contribute with some more info (I faced a similar problem in past developing a BLE client application on Android side), in Android BLE api, the discoverServices() present on GATT class is responsible to discover the services of the BLE peripheral, after this process it will invoke a user defined callback with a list of discovered services, you just need to iterate on this list until find the UUID which matches with the one passed by Franjo on his post.
 

Here you can find the BLE activity which I developed to solve a similar issue:
https://github.com/uLipe/littlebee/blob/master/app/src/main/java/com/project/hackathon/motorola/bluetoothexample/bleActivity.java

Take a look on line 159, there you will find the callback called from discoverServices, note after find the characteristic I want to listen, on line 176, I write on characteristic discovery to enable the Notification, this operation allows to XDK send data to the Android side. You can of course reuse the entire code for evaluation ,I released over MIT Licence ;).


Also take a look on line from 128, there is the method which invoke the Peripheral service discovery once a connection is made.

Let me know if this was helpful to you :D

Best
 

Felipe

0 (0 투표)
RE: How to enable BLE notifications?
응답
17. 11. 27 오후 5:00 as a reply to Felipe Neves.

Hello guys,

Thank you for the additional detailed explanation Felipe. I recommend that you consider using Felipe's insight to solve your issue, Franz, since a working example might be more useful than lengthy explanations and remote attempts at troubleshooting here.

If you have further questions, please let us know.

Kind regards,
Franjo

0 (0 투표)