The suite of example projects for the QN9080 includes a variety of use cases, but none of them covers using long attribute values. According to the BLE spec, GATT attribute values should be allowed up to 512 bytes. There is even a comment to this effect within source/common/gatt_db/macros/gatt_db_macros.h:
/*
*
* Characteristic Value Attribute Value
* - max 512 bytes
*/
However, when I attempt to modify any gPermissionFlagReadable_c characteristic to increase its size beyond 123 bytes, the debugger ends up in the HardFault_Handler as soon as my phone tries to read it the value.
gatt_db.h:
PRIMARY_SERVICE_UUID128(service_temperature, uuid_service_temperature)
CHARACTERISTIC(char_temperature, gBleSig_Temperature_d, (gGattCharPropRead_c))
VALUE(value_temperature, gBleSig_Temperature_d, (gPermissionFlagReadable_c), MAX_CHAR_SIZE, 0x00)
CCCD(cccd_temperature)
temperature_service.c:
static const uint8_t TMP_TEMP[512] = { ... };
bleResult_t Tms_RecordTemperatureMeasurement (uint16_t serviceHandle, int16_t temperature)
{
// ...
result = GattDb_WriteAttribute(handle, MAX_CHAR_SIZE, (uint8_t*)TMP_TEMP);
// ...
}
As long as MAX_CHAR_SIZE <= 123, the communication works fine. As soon as I cross that threshold, the board halts and my phone is consequently disconnected. The gatt_server_interface.h doesn't appear to expose the paging offset from Read Blob outlined in BLE Core 4.2 section 3.4.4.5, leaving me to assume that this is all handled internally to the GattDb library.
Can anyone help me figure out what I've done wrong here?
Cheers,
Ian.
Hello Ian,
I implemented this on my side and increased the temperature characteristic value size to 512 as you did and was able to successfully read the whole 512 bytes with a smartphone.
Does this issue also appear if you run the application without the debugger attached?
Can you confirm that the characteristic value has 512 bytes allocated in the gatt database? You can verify this by looking for value_temperature_valueArray in the \Debug\*.map file generated by the linker. It should be similar to:
.bss.value_temperature_valueArray
0x04000f00 0x200 ./source/common/gatt_db/gatt_database.o
0x04000f00 value_temperature_valueArray
About the Read Blob Response, you are correct. It is handled internally by the BLE host library.
I recommend removing the CCCD from the temperature characteristic if you are removing the notification or indication properties from the characteristic. The CCCD is used to enable/disable the notifications/indications so it has no use if your only property is gGattCharPropRead_c.
Let me know your results.
Best regards,
Gerardo