BLE notification transfer size

amazone
Posts: 8
Joined: Mon May 29, 2017 2:47 am

BLE notification transfer size

Postby amazone » Mon May 29, 2017 3:09 am

Hi, Is there any limitation to characteristic size for use in notifications?

The reason for asking is the following:

I have a service with a characteristic with size 120 bytes.

I turn on the notifications and get values into my android Phone, then I only get 20 bytes.

Code: Select all

esp_gatts_attr_db_t ...

 [TEST_IDX_VAL]       =
    {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&TEST_UUID, ESP_GATT_PERM_READ,
                              150, 0, NULL}},

....
....
E (18572) BT: attribute value too long, to be truncated to 20


Is the notification transfer size limited to 20 byte?
Is it possible to transmit 120 byte at a time?

plz..help !!

madscientist_42
Posts: 95
Joined: Tue Feb 21, 2017 10:17 pm

Re: BLE notification transfer size

Postby madscientist_42 » Tue May 30, 2017 2:30 pm

The ATT MTU is set to 23 bytes total. This realistically equates to 20 bytes in your notification data payload, because it does a single packet, period. Pretty much any stack is going to truncate your notification because it's larger than the MTU allows and it won't send it as a multi-packet event.

You can attempt to adjust the MTU on the Central, which would tell the Server to do the "right" things on that score. The drawback there is that your Central may/may not support the API edge to do this. Max MTU is 517 per the spec.

You can also code your app on the Central to get the notification and then do a fragmented read operation on the characteristic.

Not all API's on the Central side of the equation provide a means to request an MTU change. Modern versions of Android and iOS will- but if you go back to 4.0 era devices, it'll be hit or miss as to whether you get to be able to change it. The MTU change is the best bet- but if you're in the space I mention, you're going to have to roll something semi-custom there, with the understanding that while it'll be clumsy to implement, it'll be "portable" to pretty much anything that you want to drop onto a Central.

jaracil
Posts: 11
Joined: Sat Apr 02, 2016 4:24 pm

Re: BLE notification transfer size

Postby jaracil » Tue May 30, 2017 7:35 pm

Look at this post, it's very illustrative.
https://punchthrough.com/blog/posts/max ... nd-android

malaimo
Posts: 17
Joined: Mon Sep 25, 2017 6:28 am

Re: BLE notification transfer size

Postby malaimo » Sat Nov 04, 2017 7:32 am

You should incrase your android phone MTU size

use this api (https://developer.android.com/reference ... stMtu(int)) to increase mtu
then send your datas in callback api "onMtuChanged"

this api can only use on version 21+ (Lollipop - 5.0)

you can just test your firmware on this very useful app "nRF Connect for Mobile" :https://play.google.com/store/apps/deta ... ls-reviews

Lucas.Hutchinson
Posts: 79
Joined: Tue Apr 26, 2016 5:10 am

Re: BLE notification transfer size

Postby Lucas.Hutchinson » Sun Nov 05, 2017 8:28 pm

You can use the long characteristic read/writes to support characteristics larger than the MTU size. The ble stack will then automatically split the characteristic up into multiple packets to be sent.
However since a notifications (and indications) are only ever a single packet event, you can't use notifications with long characteristics.

One way around this is to implement your own splitting protocol on top of the ble stack. This is what I have done and it works very well.


One thing to point out:
While the BLE spec allows an mtu of 517, and adroid does dupport this.
iOS doesnt allow adjustment of MTU sizes. iOS automatically tries to negotiate a larger MTU size of 185 (since iOS 10, i think). This is not user configurable. So keep this in mind.

Who is online

Users browsing this forum: No registered users and 305 guests