I am using the following react-native-ble-manager reaction library
I am trying to perform read and write operations on a BLE device. I am successfully performing a read operation. But I get an error code of 128 when writing to a BLE device.
firstly, I include a notification for the characteristics -
BleManager.startNotification(peripheralId, serviceId, characteristicId)
Writing - like this -
converting the value of "hex" to base64 -
const base64String = new Buffer('0x00B00050D0', 'hex').toString('base64'); BleManager.write(peripheralId, serviceId, characteristicId, base64Value)
Enter Operation Return Error Code -128
:(
UPDATE - This is a code snippet to start notification and record values, the full file can be found here BluetoothLeService.java
public void writeCharacteristic(BleCharacteristic bleCharacteristic, String inputValue) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } if (!bleCharacteristic.isNotificationStarted()) { Log.w(TAG, "Notification not started please start notification"); return; } BluetoothGattCharacteristic bluetoothGattCharacteristic = bleCharacteristic.getBluetoothGattCharacteristic(); bluetoothGattCharacteristic.setValue(inputValue); mBluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic); } public void setCharacteristicNotification(BleCharacteristic bleCharacteristic) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } boolean enable = !bleCharacteristic.isNotificationStarted(); Log.d(TAG, "setCharacteristicNotification(device=" + mBluetoothDeviceAddress + ", UUID=" + bleCharacteristic.getUUID().toString() + ", enable=" + enable + " )"); BluetoothGattCharacteristic characteristic = mBluetoothGatt.getService(bleCharacteristic.getServiceUUID()).getCharacteristic(bleCharacteristic.getUUID()); mBluetoothGatt.setCharacteristicNotification(characteristic, enable); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[]{0x00, 0x00}); boolean result = mBluetoothGatt.writeDescriptor(descriptor); bleCharacteristic.setNotificationStarted(result); Log.d(TAG, "setCharacteristicNotification(device=" + mBluetoothDeviceAddress + ", UUID=" + bleCharacteristic.getUUID().toString() + ", enabled=" + result + " )"); }