Can not Read/Write long attributes on GATT Client in KW41Z BLE Stack

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can not Read/Write long attributes on GATT Client in KW41Z BLE Stack

3,770 Views
hungpv
Contributor I

Hi,

I need to program a BLE Central using GATT Client API to read and write a characteristic with 255 bytes. After connection, getting MTU is 247.

In the BLE Application Developer's Guide saying

The GATT Client module takes care of long characteristics, whose values have a greater length than can fit in a single ATT packet, transparently by issuing repeated ATT Read Blob Request When need.

When I call API GattClient_ReadCharacteristicValue with length of 255. The stack generate error 0x04 (gBleFeatureNotSupported_c) , The feature is not supported yet.

      GattClient_ReadCharacteristicValue(peerDeviceId,&myCharacteristic,255);

For write operation API, there is a parameter that allows to transfer data more than MTU -1 size.

So when I call API GattClient_WriteCharacteristicValue with this doReliableLongCharWrites set to TRUE, the stack also generates Error = 0x04, the feature not support yet.

      GattClient_WriteCharacteristicValue(peerDeviceId, &myCharacteristic, 255, Value_w, FALSE, FALSE, /*Enable          Write Long attribute*/ TRUE, NULL);

Event, I think about calling lower API, manually handles multipe read operation with offset.

   attReadBlobRequestParams_t aRdBlobReq;
   aRdBlobReq.attributeHandle = long_char_handle;
   aRdBlobReq.valueOffset = 0;
   bleResult_t result = AttClient_SendReadBlobRequest(peerDeviceId, &aRdBlobReq);
   if (gBleSuccess_c != result)
   {
      /* Handle error */
      PRINTF("ERR: GattClient Read CharacteristicLongValue 0x%x\n\r", result);
   }
ATT_ReadBlobAttributes, it returns to error 0x04 indicates that feature unsupported.


For development environment, I uses:
- SDK_2.2.1_FRDM-KW41Z
- Bluetooth 1.2.8 lib

Please let me know the support of these features.

Labels (2)
0 Kudos
Reply
8 Replies

3,418 Views
hungpv
Contributor I

Hi Sebastian

I'm sure that my ble peripheral device (on nordic nrf52840) which have long characteristic with 255 bytes. I tried writing android application for reading this characteristic, received right 255 bytes value. Even a ble central written in nrf52840 that I can issue ReadBlob Request to long attributes. It has successfully read it.

Thank you for your reference. However, the example show me a too few intructions about BLE Central implementation with read/write data if the length exceeds MTU.

Again, my question is why the GATT Client returns error code is 0x04 = (gBleFeatureNotSupported_c) when issues AttClient_SendReadBlobRequest, AttClient_SendPrepareWriteRequest, AttClient_SendExecuteWriteRequest.

I would like to know whether or not the support is on reading and writing of long characteristic on Gatt Client in the central mode?

Please confirm and provide some suggestion to me.
Thanks.

0 Kudos
Reply

3,418 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Hung,

Could you please provide more details on how this characteristic is defined in your central device?

This information should be in the gatt_db.h header file of your project.

Also, could you please provide a bit more information on if the value set as a variable length characteristic? Or is it a fixed length?

Best regards,

Sebastian

0 Kudos
Reply

3,418 Views
hungpv
Contributor I

The gatt_db.h file don't make sense in central my project for KW41Z. Because the project as BLE Central don't need to build gatt db. Only use discovery service function to get handle of characteristic from peripheral.

I can not provide publicly to you my peripheral with 255-byte characteristic. But I make sure other central work with this peripheral. even my central on QN908X works totally.

Here is my code for Gatt operation: (implemented on both KW41Z and QN908X)

static void BleApp_GattClientCallback(deviceId_t serverDeviceId,gattProcedureType_t procedureType, gattProcedureResult_t procedureResult, bleResult_t error {

   switch(procedureType) {

   case gGattProcReadCharacteristicValue_c:

   if (gGattProcSuccess_c == procedureResult) {

    if(service_data[1].char_data[1].char_handle == myCharacteristic.value.handle) /* read only with len255 */

      {

         PRINTF("[rsp] Read long value len:%d\n\r", myCharacteristic.value.valueLength);

      }

   /* Handle error */

   else {

   PRINTF("ERR_Read: %x ",error);

   if(gBleFeatureNotSupported_c == error) {

   PRINTF("The feature is not supported yet! \n\r");

   }

 }

break;

case gGattProcWriteCharacteristicValue_c:

   if (gGattProcSuccess_c == procedureResult) {

      /* wite property with len255 */

      if(service_data[1].char_data[3].char_handle == myCharacteristic.value.handle) {

         PRINTF("GATT Write response operation Success!\n\r");

      }

   else {

      PRINTF("ERR_Write: %x ",error);

      if(gBleFeatureNotSupported_c == error) {

         PRINTF("The feature is not supported yet! \n\r");

      }

      else if(gBleInvalidParameter_c == error) {

         PRINTF("Invalid Params! \n\r");

      }

   }

   break;

}

}

/* Function for read request operation. */

void CharReadLongRequest(deviceId_t peerDeviceId, uint8_t SerPosition, uint8_t CharPosition, uint16_t ValueLength)

{

   myCharacteristic.value.handle = service_data[SerPosition].char_data[CharPosition].char_handle;

   myCharacteristic.value.paValue = rdata;

   bleResult_t result = GattClient_ReadCharacteristicValue(peerDeviceId,&myCharacteristic,ValueLength);

   if (gBleSuccess_c != result)

   {

      /* Handle error */

      PRINTF("ERR: GattClient_ReadCharacteristicValue\n\r");

   }

}

/* Function for write request operation. */

void CharWriteLongRequest(deviceId_t peerDeviceId, uint8_t SerPosition, uint8_t CharPosition, uint8_t ValueLength) {

   bleResult_t result;

   myCharacteristic.value.handle = service_data[SerPosition].char_data[CharPosition].char_handle;

   if(service_data[1].char_data[3].char_handle == myCharacteristic.value.handle)

   {

   uint8_t write_long_value[255] ;

      for(uint8_t i =0;i<255;i++) {

        write_long_value[i] = 0x00;

      }

      result = GattClient_WriteCharacteristicValue(peerDeviceId, &myCharacteristic, ValueLength, write_long_value, FALSE, FALSE, /* doReliableLongCharWrites on */ TRUE, NULL);

   }

   if (gBleSuccess_c != result) {

      PRINTF("ERR: GattClient_WriteCharacteristicValue\n\r");

   }

}

/* Run test gatt request. */

uint8_t FunctionTest_Execute(int tcindex) {

PRINTF("** Execute Test function #%d ", tcindex);

switch(tcindex) {

   case 1:

      PRINTF("**\n\r");

   PRINTF("->Read long attributes 255 byte\n\r");

   CharReadLongRequest(mPeerDeviceId, 1, 1, 255);

   break;

   case 2:

   PRINTF("**\n\r");

   PRINTF("->Write long attributes 255 byte\n\r");

   CharWriteLongRequest(mPeerDeviceId, 1, 3, 255);

   break;

default:

   return 1;

}

### Output log on KW41Z ###

--Service Discovery Done & Begin Run Gatt Test function! ** Execute Test function #1 ** ->Read long attributes 255 byte ERR_Read: 4 The feature is not supported yet! ** Execute Test function #2 ** ->Write long attributes 255 byte ERR_Write: 4 The feature is not supported yet!

### Output log on QN908X ###

--Service Discovery Done & Begin Run Gatt Testcase!
** Execute Test Case #1 **
->Read long attributes 255 byte
<-longByte GATT_Read operation value len:255
<-longByte GATT_Read operation success
** Execute Test Case #2 **
->Write long attributes 255 byte
<-longByte GATT_Write operation Success!

I use all same APIs from SDK 2.2.1 on both, But result is different between KW41Z and QN908X. KW41Z  may not support these functions. 

Please help me review my code. I can provide confidentially my project by email.

Could you confirm the functionality of ble stack on KW41Z.

Regards,

VietHung

0 Kudos
Reply

3,418 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Hung, 

Could you please confirm which library is being used to implement your application? Are you using the Central-only Host library?

Could you please let me know which SDK example did you base your project on? or is it a custom made project?

Best regards,

Sebastian

0 Kudos
Reply

3,418 Views
hungpv
Contributor I

Hi Sebastian,

My project is based on SDK_2.2.1_FRDM-KW41Z. the host library used in the project are
../middleware/wireless/bluetooth_1.2.8/host/lib/lib_ble_4-2_host_central_cm0p.a
../middleware/wireless/bluetooth_1.2.8/host/lib/lib_ble_kw41z_controller.a

Regards,

VietHung

0 Kudos
Reply

3,418 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi VietHung,

 

Could you please create a Support Ticket through the support tool instead of the community?

You can submit a Support Ticket by following the steps shown in this guide https://community.nxp.com/docs/DOC-329745

After submitting the new ticket, either me or one of my colleagues will assist you further.

Take care, best regards,

Sebastian

0 Kudos
Reply

3,418 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Hung,

 

I'm going to investigate internally to see if there's some more information about this behavior.

I'll get back to you as soon as I get an answer.

Also, could you please let me know which SDK example is your project based on?

Please let me know if you need any more information.

 

Best regards,

Sebastian

0 Kudos
Reply

3,418 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Hung, I hope you're doing well!

 

Could you please confirm if the value size in the GATT database (located in the gatt_db.h header file) is set correctly for your characteristic to receive a 255 byte value?

 

If you need reference on how to edit the database for either a dynamic or static value size, could you please take a look at the following SDK examples?:

 

  • For a static size characteristic Value, the heart rate service, in the Heart Rate Sensor SDK example:
    <...\SDK_SDK_2.2.1_FRDM-KW41Z\boards\frdmkw41z\wireless_examples\bluetooth\heart_rate_sensor>
  • For a dynamic size characteristic value, the throughput characteristic is of a variable length:
    <...\SDK_SDK_2.2.1_FRDM-KW41Z\boards\frdmkw41z\wireless_examples\bluetooth\ble_shell>

 

Please let me know if you need any more information.

 

Best regards,

Sebastian

0 Kudos
Reply