0
votes

Starting from official Qt5 examples I wrote a very short piece of code which defines a GATT server characteristic:

QLowEnergyCharacteristicData chrCommand;
chrCommand.setUuid(UUID_CHR_COMMAND);
chrCommand.setValue(QByteArray(2, 0));
chrCommand.setProperties(QLowEnergyCharacteristic::Write);
const QLowEnergyDescriptorData clientConfigCommand(QBluetoothUuid::ClientCharacteristicConfiguration, QByteArray(2, 0));
chrCommand.addDescriptor(clientConfigCommand);

Then I set up the server itself: advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral); advertisingData.setIncludePowerLevel(false); advertisingData.setLocalName("test"); advertisingData.setServices(QList() << UUID_ADV_MIRROR);

QLowEnergyServiceData srvService;
srvService.setType(QLowEnergyServiceData::ServiceTypePrimary);
srvService.setUuid(UUID_SRV_SERVICE);
srvService.addCharacteristic(chrCommand);

leController = QLowEnergyController::createPeripheral();
service = leController->addService(srvService);
leController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData, advertisingData);

Where all UUIDs constants are just my own random UUIDs. It works and I can discover, bond, and write the 2-bytes to my characteristic.

I'm reading through both the Qt5 and BLE documentations but I've still some questions I cannot answer by myself:

  • how to define a characteristic with longer payload? Say a 16-byte long "string" array?

  • what is the maximum length of a single characteristic?

  • what is the maximum length of all characteristics?

  • the localName should be summed in the previous size?

1
After some trials it seems I can send data of any length - I tried up to 31 bytes. In some documents I read the maximum payload of a GATT characteristic is 22 bytes. Thus the confusion and the questions are still valid!Mark

1 Answers

1
votes

I am not familiar with the Qt BLE library but generally you have these rules:

A characteristic has a max length of 512 bytes.

There is no summed max length of all characteristics.

There are however limits when values are sent over the air:

The advertising data is divided in two parts where each part is max 31 bytes. The first part is called advertising data and the other part is called scan response data. By default only the first part is sent over the air with frequent time intervals, but a central may ask for the scan response data by sending a scan request.

Qt seems to have some library function to build the adv data but you must still beware of the max length. There is no restriction of the internal components in the advertisement data.

In a connected state, you can in a standard write request write up to 20 bytes and if you do a read request you can get at most 22 bytes in response. But the are protocol messages to be able to read and write "long values" as well but they require multiple round trips.