Read and Write characteristic is not working in serene bed shaker device

Hello,

I try read and write characteristic in serene bed shaker device using android studio.
I bond the serene bed shaker device successfully but after i can't write a characteristic.

I used no.nordicsemi.android.support.v18:scanner:1.4.3 lib for the scanning the nearest Bluetooth devices.

For the connection of device i used below code 

 @Override
public void onServicesDiscovered(final BluetoothGatt gatt, int status) {
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = sDateFormat.format(new java.util.Date());
Log.w(TAG, "Connection status changes Get service statuse: " + status + "; 时间:" + date);
if (status == BluetoothGatt.GATT_SUCCESS) {
List<BluetoothGattService> gattServices = gatt.getServices();
if (gattServices == null) return;

BluetoothLeService.ConnectDevice theDev = findConnectedDevice(gatt.getDevice().getAddress());
if (theDev != null) {
if (theDev.mGatt == gatt) {
theDev.connectState = STATE_CONNECTED;
Log.i(TAG, "same");
} else {
Log.i(TAG, "difrent");

closeDevice(gatt.getDevice().getAddress());

theDev = new BluetoothLeService.ConnectDevice(gatt);
theDev.connectState = STATE_CONNECTED;
mHaveConnectDevices.add(theDev);
}
} else {
theDev = new BluetoothLeService.ConnectDevice(gatt);
theDev.connectState = STATE_CONNECTED;
mHaveConnectDevices.add(theDev);
}


for (BluetoothGattService gattService : gattServices) {
//-----Characteristics-----//
List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
// BluetoothGattCharacteristic tmpgattCharacteristic = null;
for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {

String uuid = gattCharacteristic.getUuid().toString();
Log.i(TAG, "uuid: " + gattCharacteristic.getUuid().toString());
Log.i(TAG, "THE PROPERTY: " + gattCharacteristic.getProperties());

if (uuid.equalsIgnoreCase(UUID_WRITE_KEY) == true) {
Log.i(TAG, "Connection status changes Get service WRITE");
int property = gattCharacteristic.getProperties();
if ((property & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0) {
theDev.isNoResponse = true;
} else if ((property & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0) {
theDev.isNoResponse = false;
}

theDev.mCharacteristic = gattCharacteristic;
// theDev.mCharacteristic.setWriteType(BluetoothGattCharacteristic.PROPERTY_WRITE);

gatt.readCharacteristic(gattCharacteristic);
// gatt.setCharacteristicNotification(gattCharacteristic, true);


if (mGerServerTimer != null) {
mGerServerTimer.cancel();
;
mGerServerTimer = null;
}
if (mOnConnectListener != null) {
mOnConnectListener.onConnect(gatt, true, true);
}

} else if (uuid.equalsIgnoreCase(UUID_READ_KEY) == true) {
Log.i(TAG, "Connection status changes Get service READ");
// gatt.setCharacteristicNotification(gattCharacteristic, true);
setCharacteristicNotification(gatt, gattCharacteristic, true);
}
}
}

} else {

}
}

public void setCharacteristicNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
boolean enabled) {

boolean isEnableNotification = gatt.setCharacteristicNotification(characteristic, enabled);

if (isEnableNotification) {
List<BluetoothGattDescriptor> descriptorList = characteristic.getDescriptors();
if (descriptorList != null && descriptorList.size() > 0) {
for (BluetoothGattDescriptor descriptor : descriptorList) {
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
}
}
}
}

@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {

Log.e("Read", characteristic.toString());

}
}

@Override
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {

Log.e("Read", characteristic.toString());

}
};
Related