2
votes

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?

1

1 Answers

1
votes

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.