chipweinberger/flutter_blue_plus

[Help]: (code: 13) GATT_INVALID_ATTRIBUTE_LENGTH

Closed this issue · 12 comments

FlutterBluePlus Version

1.14.12

Flutter Version

3.10.5

What OS?

Android, iOS

OS Version

Android 13 - IOS 14.5.1

What happened?

Try to write 509 byte to pass a file and this error occurred

Error general execute command: FlutterBluePlusException: writeCharacteristic: (code: 13) GATT_INVALID_ATTRIBUTE_LENGTH

Logs

[FBP-Android] onMethodCall: writeCharacteristic
[FBP-Android] onCharacteristicChanged: uuid: ed2af5d6-d595-11ea-87d0-0242ac130003
[FBP-Android] onCharacteristicWrite: uuid: ed2af5d6-d595-11ea-87d0-0242ac130003 status: 13
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   DeviceFirmwareUpgradeBloc.upgradeFirmwareNotification.<anonymous closure> (package:xxxx_core/features/firmware_upgrade/device/bloc/device_firmware_upgrade_bloc.dart:209:14)#1   _rootRunUnary (dart:async/zone.dart:1407:47)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 11:41:42.524 (+0:02:05.759071)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 🐛 Upgrade notify [0, 0, 24, 0, 0, 0]
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   BLECommandsTailBloc._executeCommand (package:xxxx_core/features/bluetooth/bloc/ble_commands_tail_bloc.dart:58:14)#1   <asynchronous suspension>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 11:41:42.545 (+0:02:05.779935)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Error general execute command: FlutterBluePlusException: writeCharacteristic: (code: 13) GATT_INVALID_ATTRIBUTE_LENGTH
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
D/[FBP-Android]( 3662): [FBP-Android] onMethodCall: writeCharacteristic
D/[FBP-Android]( 3662): [FBP-Android] onCharacteristicWrite: uuid: ed2af5d6-d595-11ea-87d0-0242ac130003 status: 13
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   BLECommandsTailBloc._executeCommand (package:xxxx_core/features/bluetooth/bloc/ble_commands_tail_bloc.dart:58:14)#1   <asynchronous suspension>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ 11:41:42.651 (+0:02:05.885696)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Error general execute command: FlutterBluePlusException: writeCharacteristic: (code: 13) GATT_INVALID_ATTRIBUTE_LENGTH
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
D/[FBP-Android]( 3662): [FBP-Android] onCharacteristicChanged: uuid: ed2af5d6-d595-11ea-87d0-0242ac130003

is 1.14.12 the first version with this problem?

how many bytes can you successfully write at most with characteristic.write(...)? do smaller writes work?

what is your MTU?

I think your problem is that you need to wait for the requestMtu to finish.

your mtu is too small

i saw it also in the older version 1.4.0 but only in IOS with the new version also in android
The mtu is 512
Also try with smaller writes

can you try using writeLarge? make sure the mtu is set correctly

import 'dart:math';

// split large writes
extension WriteLarge on BluetoothCharacteristic {
  Future<void> writeLarge(List<int> value, int mtu, {int timeout = 15}) async {
    int chunk = mtu-3;
    for (int i = 0; i < value.length; i += chunk) {
      List<int> subvalue = value.sublist(i, min(i + chunk, value.length));
      await write(subvalue, withoutResponse:false, timeout: timeout);
    }
  }
}

i can't use it because i have to wait the answer form the other side

Your firmware does not allow 512 bytes writes.

update your firmware, or write less at one time.

ok i'll check we the firmware guys.
Thanks

I have same issue, is this solved?

Debug log

D/[FBP-Android]( 9124): [FBP-Android] onMethodCall: requestMtu
D/BluetoothGatt( 9124): configureMTU() - device: CB:4E:FD:**:**:** mtu: 512
D/BluetoothGatt( 9124): onConfigureMTU() - Device=CB:4E:FD:**:**:** mtu=200 status=0
D/[FBP-Android]( 9124): [FBP-Android] onMtuChanged: mtu: 200 status: 0
D/[FBP-Android]( 9124): [FBP-Android] onMethodCall: writeCharacteristic
D/BluetoothGatt( 9124): writeCharacteristic() - uuid: 00002a00-0000-1000-8000-00805f9b34fb
D/BluetoothGatt( 9124): onCharacteristicWrite() - Device=CB:4E:FD:**:**:** handle=3 Status=13
D/[FBP-Android]( 9124): [FBP-Android] onCharacteristicWrite: uuid: 00002a00-0000-1000-8000-00805f9b34fb status: 13
I/flutter ( 9124): FlutterBluePlusException: writeCharacteristic: (code: 13) GATT_INVALID_ATTRIBUTE_LENGTH

This is write I want

await c.write([0xaa, 0xaa, 0xcc, 0x32, 4, 4, 4, 0xFF, 2, 2, 1, 0x02, 0x02, 0x01, 0x01], allowLongWrite: true);

How can I split write command?

the problem is your device firmware.

your device has a small limit configured for characteristic size.

I confirm that the problem was firmware side!