Skip to content

Commit

Permalink
Improve requestMTU() docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fotiDim committed Feb 16, 2025
1 parent 1525628 commit 146323a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,34 @@ UniversalBle.enableBluetooth();
UniversalBle.disableBluetooth();
```

### Request MTU

This method will **attempt** to set the MTU (Maximum Transmission Unit) but it is not guaranteed to succeed due to platform limitations. It will always return the current MTU.

```dart
int mtu = await UniversalBle.requestMtu(widget.deviceId, 247);
```

#### Platform Limitations

On most platforms, the MTU can only be queried but not manually set:

- **iOS/macOS**: System automatically sets MTU to 185 bytes maximum
- **Android 14+**: System automatically sets MTU to 517 bytes for the first GATT client
- **Windows**: MTU can only be queried
- **Linux**:
- **Web**: No mechanism to query or modify MTU size

#### Best Practices

When developing cross-platform BLE applications and devices:

- Design for default MTU size (23 bytes) as default
- Dynamically adapt to use larger packet sizes when the system provides them
- Take advantage of the increased throughput when available without requiring it
- Implement data fragmentation for larger transfers
- Handle platform-specific MTU size based on current value

## Command Queue

By default, all commands are executed in a global queue (`QueueType.global`), with each command waiting for the previous one to finish.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/universal_ble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class UniversalBle {
}

/// Request MTU value.
/// `requestMtu` is not supported on `Linux` and `Web.
/// It will **attempt** to set the MTU (Maximum Transmission Unit) but it is not guaranteed to succeed due to platform limitations.
/// It will always return the current MTU.
static Future<int> requestMtu(String deviceId, int expectedMtu) async {
return await _bleCommandQueue.queueCommand(
() => _platform.requestMtu(deviceId, expectedMtu),
Expand Down

0 comments on commit 146323a

Please sign in to comment.