8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BLE で送信するパケットのサイズを拡張する際の注意点 (Android)

Posted at

BLE で一度に送信できるデータサイズの上限はデフォルトでは 20 byte ほどですが、拡張することができます。
その方法とその際の注意点をまとめました。
※ central が Android の場合の方法です。

拡張

BluetoothGatt.requestMtu(int mtu) というメソッドで拡張することができます。
上限は 512 byte です。

注意点

下記のように、拡張と write などのリクエストを続けて行ってしまうと、 peripheral が反応してくれません。

mBluetoothGatt.requestMtu(50);
mBluetoothGatt.writeCharacteristic(characteristic);

そのため、拡張のリクエストを送ったperipheral でパケットサイズの変更が終わるまで待つ必要があります。
peripheral での処理が終わると central の BluetoothGattCallback.onMtuChanged() が呼ばれます。
なので、 BluetoothGattCallback.onMtuChanged() が呼ばれるのを待って write などの処理を開始するとうまく動作させることができます。

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?