Android bluetooth low energy (ble) writeCharacteristic callback callback

I am using an Android application using BLE Api (SDK 18) and I have a problem that the data transfer process is delayed very slowly. This is my magazine.

03-12 16: 20: 05.121: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 06.272: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 06.972: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 08.254: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 10.055: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 11.257: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 12.478: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 14.250: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 14.960: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 16.242: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 16.402: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 20.225: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 20.526: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 24.219: D / Bluetooth Gatt (13578): onCharacteristicWrite () - Device = ... UUID = ... Status = 0

03-12 16: 20: 25.360: D / Bluetooth Gatt (13578): writeCharacteristic () - uuid: ...

03-12 16: 20: 27.222: D/BluetoothGatt (13578): onCharacteristicWrite() - Device =... UUID =... Status = 0

, , onCharacteristicWrite, , onCharacteristicWrite .

Android, , , , .

:

private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
......
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    mSending = false;
}
};

private void writeCharacteristic() {
    .....

    mGattCharacSetIntensity.setValue(data);
    mGattCharacSetIntensity.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
    mBluetoothGatt.writeCharacteristic(mGattCharacSetIntensity);
    return;
}

EDIT: iPhone ( BLE AppStore), BLE ( 0,5 ), . SPEED UP Android BLE?

EDIT: WriteType BluetoothGattCharacteristic WRITE_TYPE_NO_RESPONSE, , Android writeCharacteristic CallBack, , lood, Android - ( 3 ).

+4
4

BLE , , , , . 7,5 4 , .

, , , , . , , BLE , .

+5

. , , Gatt. writeCharacteristic() onCharacteristicWrite(). (1500 ), () () gatt . .

Bluetooth . gatt 15 , . .

, onServicesDiscovered(). .

+2

This is also a problem for me. If you delay calls in the debugger, you can confirm that there is a delay when recording to the BLE radio controls. I will queue in my application to handle the delay.

Here is what I do for queue commands:

public void sendWriteCommandToConnectedMachine(byte[] commandByte) {
    if(commandByte.length > 20)
        dissectAndSendCommandBytes(commandByte);
    else
        queueCommand(commandByte); //TODO - need to figure out if service is valid or not
}

private void queueCommand(byte[] command) {
    mCommandQueue.add(command);

    if(!mWaitingCommandResponse)
        dequeCommand();
}

Here is what I do to remove BLE commands

private void dequeCommand() {
    if(mCommandQueue.size() > 0) {
        byte[] command = mCommandQueue.get(0);
        mCommandQueue.remove(0);
        sendWriteCommand(command);
    }
}

here is my characteristic recording method

@Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
        if(status != BluetoothGatt.GATT_SUCCESS)
            logMachineResponse(characteristic, status);     

        mWaitingCommandResponse = false;
        dequeCommand();
    }
+1
source

You will need to implement your flow control, do not start writing until OnCharacteristicWrite is sent for the previous record

+1
source

Source: https://habr.com/ru/post/1531302/


All Articles