Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requesting MTU with Bluetooth Low Energy connection on Android 4.3-4.4 (API 18-20)

I have a Bluetooth Low Energy Application which requires an MTU size above the default 23 bytes.

Though Android introduced BluetoothGatt#requestMTU() in API 21, is there any way, including use of private APIs, to accomplish this pre API 21?

like image 595
dbro Avatar asked Jun 17 '15 23:06

dbro


People also ask

What is MTU in Bluetooth?

Maximum Transfer Unit (MTU) specifies the number of bytes that can be sent within one GATT operation. In other words, it's the number of bytes that can be sent within two connection intervals. MTU size can be set for each connection. However, it has an upper limit, which varies with Bluetooth stack versions.

What is a Bluetooth low energy device?

Bluetooth Low Energy is a power-conserving variant of Bluetooth personal area network (PAN) technology, designed for use by Internet-connected machines and appliances. Also marketed as Bluetooth Smart, Bluetooth LE was introduced in the Bluetooth 4.0 specification as an alternative to Bluetooth Classic.


1 Answers

If you have control over the peripheral device, you can issue an MTU request (ATT_OP_MTU_REQ, opcode 0x02) from the peripheral. Android is capable of larger GATT MTUs (update: 517 bytes is the maximum value), if requested by the peripheral, and will happily send an according ATT_OP_MTU_RESP.

The only tricky thing is that the MTU exchange may not overlap with a fragmented read/write. One workaround might be a client-side sleep at a given time of the handshake, where the peripheral sends an MTU request. Another possible workaround would be a READ or WRITE on a "magic" characteristic that triggers the MTU exchange.

However, with an increased MTU, I'm much more often receiving Status=133 errors, possibly caused by a higher packet error rate with larger packets?

like image 136
ge0rg Avatar answered Oct 13 '22 00:10

ge0rg