I'm trying to writeCharacteristic()
to a BLE device.
I used Google example app to establish the connection, the connection is fine. I can see the BLE Services and the services Characteristics.
The writeCharacteristic()
method return true and the onCharacteristicWrite()
callback return status BluetoothGatt.GATT_SUCCESS
but nothing happening with the device:
I tried all the solutions in stack overflow and nothing helps.
Here is my code:
In the BluetoothLeService
class i have sendData()
method, which gets a byte[]
I'm sending each command separately because of the maximum payload of 33 bytes.
public void sendData(byte[] data) {
String lService = "71387664-eb78-11e6-b006-92361f002671";
String lCharacteristic = "71387663-eb78-11e6-b006-92361f002671";
BluetoothGattService mBluetoothLeService = null;
BluetoothGattCharacteristic mBluetoothGattCharacteristic = null;
if (mBluetoothGattCharacteristic == null) {
mBluetoothGattCharacteristic = mBluetoothGatt.getService(UUID.fromString(lService)).getCharacteristic(UUID.fromString(lCharacteristic));
}
mBluetoothGattCharacteristic.setValue(data);
boolean write = mBluetoothGatt.writeCharacteristic(mBluetoothGattCharacteristic);
}