setMtu method

  1. @override
Future<int?> setMtu({
  1. required int newMtu,
})
override

setMtu sets the MTU size for the BLE connection. The MTU size is the maximum number of bytes that can be sent in a single packet, also, MTU means Maximum Transmission Unit and it is the maximum size of a packet that can be sent in a single transmission.

The return value is the new MTU size, after a negotion with the peripheral.

Implementation

@override
Future<int?> setMtu({required int newMtu}) async {
  if (_connectedDevice == null) {
    log("Not connected to any device");
    return null;
  }

  final service = _connectedDevice!.gattServices.firstOrNull;
  if (service == null) {
    log("Service not found");
    return null;
  }

  final characteristic = service.characteristics.firstOrNull;
  if (characteristic == null) {
    log("Characteristic not found");
    return null;
  }

  return characteristic.mtu;
}