为什么有响应和无响应的 MTU 不同?

Why is the MTU different for With Response vs Without Response?

在 iOS 上,当我请求 MTU 时,我得到 .withoutResponse.withResponse 的不同值。我意识到它可能会有所不同,因为该函数采用该参数,但为什么会有所不同?

这是设备 (BLE 4.2):

(lldb) po peripheral.maximumWriteValueLength(for: .withoutResponse)
182

(lldb) po peripheral.maximumWriteValueLength(for: .withResponse)
512

在另一台设备 (BLE 5) 上我得到:

(lldb) po peripheral.maximumWriteValueLength(for: .withoutResponse)
509

(lldb) po peripheral.maximumWriteValueLength(for: .withResponse)
512

Write Without Response与MTU直接相关。 (MTU - 3).

当您使用 writeWithResponse 时,iOS 可以执行 Write With Response(最大值长度为 MTU - 3),或“Write Long Characteristic Values”,它使用多个 ATT 事务写入值。在后一种情况下,唯一的限制因素是特征值的最大长度,标准将其设置为 512 字节。