Variable data length

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

lets say I have a characteristic:

    CHARACTERISTIC_UUID128 (0x0029, HANDLE_HELLO_SENSOR_VALUE_NOTIFY, UUID_HELLO_CHARACTERISTIC_NOTIFY,

                           LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_NOTIFY | LEGATTDB_CHAR_PROP_INDICATE,

                           LEGATTDB_PERM_READABLE, 7),

        'H','e','l','l','o',' ','0',

now I want to change the message and its length and then send it:

void update_message( UINT8 *data, INT32 len)

{

  int i;

  BLEPROFILE_DB_PDU db_pdu;

  bleprofile_ReadHandle(HANDLE_HELLO_SENSOR_VALUE_NOTIFY, &db_pdu);

  for( i = 0; i<len; i++)

  {

       db_pdu.pdu = data;

  }

  db_pdu.len = len;

  bleprofile_WriteHandle(HANDLE_HELLO_SENSOR_VALUE_NOTIFY, &db_pdu);

  ble_trace1("len1: %d\n", db_pdu.len);


  bleprofile_ReadHandle(HANDLE_HELLO_SENSOR_VALUE_NOTIFY, &db_pdu);

  ble_trace1("len2: %d\n", db_pdu.len);

}

the problem I am having with my above function is that the data gets modified correctly, but the length remains the same.

lets say I pass the new length to be 3.

At line 15 the output I get is 3.

but at line 18, after reading the handle back the output goes back to 7.

Then when I send my data over BLE, I send 3 bytes of my new data plus the original remaining bytes.

Is there a way to have the length of the data payload change? How can i do this?

Thank you

1 Solution

Try to add LEGATTDB_PERM_VARIABLE_LENGTH bit to the characteristic definition.  For example

LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ
| LEGATTDB_PERM_VARIABLE_LENGTH

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

I had this same problem. It is weird that db_pdu.len doesn't actually change when you assign it. What I did was store the real length in a different variable, then pass that actual number to ble_sendNotification(). This transmits the correct number of bytes. Haven't tried a read request of the characteristic though...

0 Likes
Anonymous
Not applicable

thanks odbol, I found a workaround for this as well...

Now I am having a similar problem, but on the write side. And I cannot find a workaround. The Hello example allows for 1 byte to be written to HANDLE_HELLO_SENSOR_CONFIGURATION. I modified it to allow for 10:

    CHARACTERISTIC_UUID128_WRITABLE (0x002c, HANDLE_HELLO_SENSOR_CONFIGURATION, UUID_HELLO_CHARACTERISTIC_CONFIG,

                                     LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_WRITE,

                                     LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ,  10),

        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

But in hello_sensor_write_handler() no matter what I send (even if I send 1 byte) I receive a length of 10. How can I find the true length of what was received? Could it be a problem with my configuration?

int hello_sensor_write_handler(LEGATTDB_ENTRY_HDR *p)

{

    UINT8  writtenbyte;

    UINT16 handle   = legattdb_getHandle(p);

    int    len      = legattdb_getAttrValueLen(p);

    UINT8  *attrPtr = legattdb_getAttrValue(p);

    // do some noise

    //bleprofile_BUZBeep(bleprofile_p_cfg->buz_on_ms);

    ble_trace2("hello_sensor_write_handler: handle %04x len %d\n", handle, len); // modified

0 Likes

Try to add LEGATTDB_PERM_VARIABLE_LENGTH bit to the characteristic definition.  For example

LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ
| LEGATTDB_PERM_VARIABLE_LENGTH

0 Likes
Anonymous
Not applicable

that did it. thank you!

0 Likes