I am working on a BLE project using Android. I want to write characteristic data and send it to a BLE chip.
I want to rewrite ISEN_Toulon
I used this code to write characteristic data, but data "ISEN_Toulon"
isn't replaced by "TEST"
as expected.
private BluetoothGattCharacteristic mWriteCharacteristic;
private final ExpandableListView.OnChildClickListener servicesListClickListner =
new ExpandableListView.OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition, long id)
{
if (mGattCharacteristics != null) {
final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition).get(childPosition);
final int charaProp = characteristic.getProperties();
.....
// READ
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
// If there is an active notification on a characteristic, clear
// it first so it doesn't update the data field on the user interface.
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(
mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}
mBluetoothLeService.readCharacteristic(characteristic);
Log.d("myTag", "1");
}
// NOTIFY
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
mNotifyCharacteristic = characteristic;
mBluetoothLeService.setCharacteristicNotification(
characteristic, true);
Log.d("myTag", "2");
}
// WRITE
characteristic.setWriteType(BluetoothGattCharacteristic.PROPERTY_WRITE);
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
characteristic.setWriteType(BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE);
mWriteCharacteristic = characteristic;
String str = "TEST";
byte[] strBytes = str.getBytes();
characteristic.setValue(strBytes);
writeCharacteristic(characteristic)
return true;
}
return false;
}
};