2 months, 2 weeks ago.

Increase maximum MTU size for write in a GATT Characteristic with nRF52-DK


Im trying to write into a GATT Characteristic, but as we know by default we only have 20 bytes available. How can I increase this value using the nRF52-DK board and Mbed? I tried using the GATTCharacteristic generic class, but the GATT Server crashes if I send more than 20 bytes.

This is my custom GATT Server code:

  1. ifndef BLE_TOF_SERVICE_H
  2. define BLE_TOF_SERVICE_H
  1. include "ble/BLE.h"

class TOFService { public: const static uint8_t TOF_CHAR_ARRAY_SIZE = 100; const static uint16_t CUSTOM_TOF_SERVICE_UUID = 0xA000; const static uint16_t TOF_CHAR_WRITE_CHARACTERISTIC_UUID = 0xA001;

TOFService(BLE& _ble) : ble(_ble), writeCharArrayCharacteristic(TOF_CHAR_WRITE_CHARACTERISTIC_UUID, writeValue) writeCharArrayCharacteristic(TOF_CHAR_WRITE_CHARACTERISTIC_UUID, writeBuffer, 1, 100, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES) { static bool serviceAdded = false; /* We should only ever need to add the information service once. */ if (serviceAdded) { return; }

GattCharacteristic *charTable[] = {&writeCharArrayCharacteristic};

GattService TOFService(CUSTOM_TOF_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));

ble.gattServer().addService(TOFService); serviceAdded = true; }

GattAttribute::Handle_t getValueHandle() const { return writeCharArrayCharacteristic.getValueHandle(); }

private: BLE& ble;

uint8_t writeBuffer[TOF_CHAR_ARRAY_SIZE];

WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeBuffer)> writeCharArrayCharacteristic; GattCharacteristic writeCharArrayCharacteristic; };

  1. endif /* #ifndef BLE_TOF_SERVICE_H*/

Thank you very much.

Comment on this question

1 Answer

2 months, 2 weeks ago.

Hi Javier,

What BLE stack are you using? Nordic SoftDevice or Arm Cordio?

What's the Mbed OS version?

Could you attach the information as GATT server crashed?

We had an issue about sending data exceeding size of MTU and it's already fixed in latest Mbed OS, could you take a look is this similar to your scenario?

Any further information would better for us to help on this question.

Thanks, Desmond, team Mbed

Thank you very much. I had an obsolete version of Mbed. I actualized the version in the Mbed online compiler and it works.

posted by Javier Vargas 01 Feb 2019

Thanks @Desmond Chen, for me this is also working

I have another issue though, when trying to negotiate a higher MTU from a central nRF52DK (programmed using nRF5SDK), to a peripheral nRF52DK (programmed with mbedOS), I am not able to send more than 23 Bytes. For instance, if I ask an update ATT MTY to 247 from central, the answer from my mbedOS peripheral is still 23 bytes although my write characteristic accepts more bytes. Do I need to add anything to my MBED code?


posted by Mario Briceño Gonzalez 06 Feb 2019

To post an answer, please log in.