2

I am using an android device with Android 5.1 (Bluetooth 4.0) and a MCU Board which has Bluetooth 4.2.

On my MCU side i am updating my Gatt Characteristic in a Loop just to make sure, that i know if the data i am writing inside is consistent. before i am writing it inside the gatt database i am using a crc check.

on my android side i just have a thread which reads the characteristic out of that gatt database and directly after that i have the same crc but it seems like 50% of the values are corrupt (which doesn't make sense from my side). i know that the data i am writing in my gatt database is correct so i guess the issue is with reading the characteristic several times in a thread.

i've already tried to read the characteristic via notifications on my android side but the bluetoothleservice is never jumping into the OnCharacteristicChanged callback.

my characteristic update Looks like this

tmpGatt.readCharacteristic(characteristic);

and the characteristic is filtered by the uuid before

for(int i = 0; i<Services.size(); i++){
                Characteristics = Services.get(i).getCharacteristics();
                for(int c=0;c < Characteristics.size();c++){
                    UUID myUUID = Characteristics.get(c).getUuid();
                    if(myUUID.toString().equals("354a1b8e-7597-11e6-8b77-86f30ca893d3")){
                        characteristic = Characteristics.get(c);
                        //refExternalData.getRefBluetoothGatt().readCharacteristic(characteristic);
                        descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
                        Log.i("BLE", "Characteristic " + myUUID.toString() + " found");
                    }
                }
            }

so do i Need to do anything Special to re-read the gattcharacteristic?

B. Ben
  • 109
  • 1
  • 9

1 Answers1

1

Did you follow the procedures at https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#notification in order to enable notifications?

When you issue readCharacteristic, you are not allowed to issue a new readCharacteristic until you have got the onCharacteristicRead. Or actually you are not allowed to send ANY new request (readCharacteristic, writeCharacteristic, readDescriptor, writeDescriptor) until a previous request has completed. This is because there may only be one outstanding GATT request at a time and there is no internal queue.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • i've switched back to the BLE example app right now just to be sure and the onCharacteristicRead is getting triggered if i am pushing the characteristic Name but the data is still corrupt. so do you think the Problem is at the app side or at the mcu side? – B. Ben Oct 04 '16 at 09:50
  • 1
    If data is corrupt it is definitely problem on the MCU / sender side. Over the air, the payload is already CRC-protected according to the BLE standard. – Emil Oct 04 '16 at 10:48
  • i'll recheck my code than, if i find the Problem ill post it here. thanks – B. Ben Oct 04 '16 at 11:01
  • the problem was that i've set the descriptor to descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); and not to descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);. Because of i was using indication on my GATT SERVER... – B. Ben Oct 10 '16 at 09:10