Hello,
I am having severe Problems with the difference in the way BTool and Android access BLE devices.
With BTool I can Read by 16-bit UUID and with the Handle, and wirte data with the Handle.
With Andorid I seem to be able to only write Data using a 128-bit UUID.
Is there any way to address Characteristics, read and write descriptors by their Handle's in Andorid ?
The way I go now is to discover all services, if the UUID matches a Service I want ( using a string compare, UGH! ) I copy the Object and access it from there on. I think this is weird. There should be a more "direct" way to access a Service, i.e. Blindly, without a prior scan of the Device.
I have a KeyFob from the CC2541DK-Mini Kit. I am trying to do everything I do with the BTool, just via Android. I have written code that can get Notified on Keypresses, and I can make the Buzzer beep.
However I seem not to be able to get the accelerometer running. (It works fine with BTool)
I am trying something like this :
1) Get Services
mBluetoothGatt.discoverServices();
2) Get UUIDs of wanted Characteristics
onServicesDiscovered(BluetoothGatt gatt, int status) {
listOfServices = mBluetoothGatt.getServices();
// iterate over listOfServices
listOfCharacteristics = serviceList_Item.getCharacteristics();
// iterate over listOfCharacteristics
mUuid = characteristicsList_Item.getUuid();
if (mUuid.contains("FFA1")) acc_EN = characteristicsList_Item
if (mUuid.contains("FFA3")) acc_X = characteristicsList_Item
if (mUuid.contains("FFA4")) acc_Y = characteristicsList_Item
if (mUuid.contains("FFA5")) acc_Z = characteristicsList_Item
3) Activate Notifications
mBluetoothGatt.setCharacteristicNotification(acc_EN, true);
mBluetoothGatt.setCharacteristicNotification(acc_X, true);
mBluetoothGatt.setCharacteristicNotification(acc_Y, true);
mBluetoothGatt.setCharacteristicNotification(acc_Z, true);
[Upto here everything works fine, the above calls end with a success (return ture)]
4) Move the Keyfob
Take Keyfob in hand and fiddle with it.
5) Callback
// At this point I would expect that the BluetoothGattCallback is called and onCharacteristicChanged is called.
But nothing happens. Although using the same scheme works fine for the Keypresses on the Keyfob.
The only thing I can think of is that I should NOT call setCharacteristicNotification for the three axes, but instead write a 01:00 to their corresponding settings. But I can't do that, since all of them have the same UUID.
Which makes sense in the context of this post :
http://e2e.ti.com/support/low_power_rf/f/538/t/86482.aspx
Where it is explained that the UUID is the "Type" and the Handle is the "Address". But I cannot access the "Address" from within Android. (Or I am simply doing something incredibly stupid, but can't see it myself.)
I have also looked into BluetoothGattCharacteristic.getInstanceId() from the Andorid API. The explanation says "If a remote device offers multiple characteristics with the same UUID, the instance ID is used to distuinguish between characteristics."
This looked like it could be a fancy way to say "This is the Address". But it always returns zero, no changes ever.
Hope someone can halp me out with this.
This is not specific to the Accellerometer, but in general about Handle's and UUID with Android.