How to increase MTU size on GATT - Server

Abhiram
Posts: 22
Joined: Mon Apr 24, 2017 5:09 pm

How to increase MTU size on GATT - Server

Postby Abhiram » Mon Jul 17, 2017 12:35 pm

Hi , all

I wanted forums help in knowing how can I increase the size of BLE MTU = 500 bytes for GATT Server. ?

so that any client connecting to this server is aware of the modified BLE MTU = 500 Bytes , and not 23 bytes, ( How this will be conveyed to the Client ) ?

I changed the GATT_DEF_BLE_MTU_SIZE = 23 to 500 in gatt_api.h , but I see the change is not taken. If I exchange the packet of size 30 , I get the error message as " BT: attribute value too long, to be truncated to 22". Or my services or characteristic doesn't get displayed on the Client application ( NRFConnect)

mh-dev
Posts: 25
Joined: Mon Nov 30, 2015 5:14 am

Re: How to increase MTU size on GATT - Server

Postby mh-dev » Mon Jul 17, 2017 1:33 pm

The constant you mentioned is used by the gatt client not the server.

Theoretically the client can request an increase of the MTU size, but I never tested it.

Abhiram
Posts: 22
Joined: Mon Apr 24, 2017 5:09 pm

Re: How to increase MTU size on GATT - Server

Postby Abhiram » Mon Jul 17, 2017 1:36 pm

Thanks mh-dev

So would you say that its only on client request , server can change the default MTU size ?
Any way for server to increase the size of its MTU ( to be used in characteristic - attribute ) and convey it to client while connecting ?

Thanks for help

mh-dev
Posts: 25
Joined: Mon Nov 30, 2015 5:14 am

Re: How to increase MTU size on GATT - Server

Postby mh-dev » Mon Jul 17, 2017 1:45 pm

I don't know if there's a way to force this from the server.
My research related to android clients tells me so far that the MTU size is hard coded at least for older devices and can not be changed.

What I use so far is the auto response with the service table. The ESP-IDF SDK is in this mode able to perform long writes. That allows to send and receive up to 512 bytes. It does this via a multi packet protocol, but you don't have to manually deal with that. Don't expect this be fast. I might do some research how this can be achieved without auto response. Since this has also drawbacks.
Be aware that to my knowledge that a bug that I reported a few days ago is still not fixed. This bug has problems if you set the attribute via esp_ble_gatts_set_attr_value in this mode. My bug ticket contains a fix that you can apply locally if you need it.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: How to increase MTU size on GATT - Server

Postby kolban » Mon Jul 17, 2017 2:08 pm

Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

mh-dev
Posts: 25
Joined: Mon Nov 30, 2015 5:14 am

Re: How to increase MTU size on GATT - Server

Postby mh-dev » Mon Jul 17, 2017 2:19 pm

kolban wrote:This API might be a clue ...

http://esp-idf.readthedocs.io/en/latest ... t8uint16_t
This should have an effect if the the client request an MTU size increase.
All files that contain gattc instead of gatts are for the client library.

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

Re: How to increase MTU size on GATT - Server

Postby Lucas.Hutchinson » Tue Jul 18, 2017 2:59 am

Hi All,

As previously mentioned it is the gatt client that needs to request an MTU change.
The gatt sever is unable to change the mtu size without a request from the gatt client.

I have tested this with the esp32 and it works very well.
In my case my gatt client always requests an MTU change of a peripheral on connection. If the peripheral doesnt support the new MTU, this will result in a failed MTU update.

On android phones (using the nrf Connect app) you can request an MTU change up to the max allowed by the BLE standard (517)

On iOS i have found that this MTU change request is not allowed to be performed by user code on a user app. However I have also found that an MTU change request is automatically negotiated by the iOS BLE stack on connection to a peripheral. from iOS 10+ the requested MTU size is 185 (various reasons for this related to very low level ble stack operations, and optimisations).

Hope this helps.

Abhiram
Posts: 22
Joined: Mon Apr 24, 2017 5:09 pm

Re: How to increase MTU size on GATT - Server

Postby Abhiram » Tue Jul 18, 2017 10:32 am

Thanks Lucas.Hutchinson for your comments , you have mentioned "On android phones (using the nrf Connect app) you can request an MTU change up to the max allowed by the BLE standard (517) " - Could please let me know how we could do this ?

Because I see " Note: The source code of nRF Connect is not available. " @ https://github.com/NordicSemiconductor/ ... RF-Connect

mh-dev
Posts: 25
Joined: Mon Nov 30, 2015 5:14 am

Re: How to increase MTU size on GATT - Server

Postby mh-dev » Tue Jul 18, 2017 12:09 pm

Increasing the MTU size on android requires version 21+ (Lollipop - 5.0)

The related API is https://developer.android.com/reference ... stMtu(int)

SW_Adnan
Posts: 4
Joined: Wed May 10, 2017 10:55 am

Re: How to increase MTU size on GATT - Server

Postby SW_Adnan » Thu Jul 20, 2017 12:51 pm

Hi all,

I understand that to increase the MTU size the request has to come from the client. The server then replies with the maximum MTU it can support.

It seems that for the server, the MTU exchange request is handled by the Bluedroid stack. Is there a way to change the max MTU that is supported by the server?

Also there is esp_ble_gap_set_pkt_data_len in the GAP API, I don't really understand what is the purpose of this function. Does it have anything to do with the MTU?

Cheers

Who is online

Users browsing this forum: Bing [Bot] and 75 guests