4 Replies Latest reply on May 1, 2014 4:10 PM by userc_3560

    Variable data length



      lets say I have a characteristic:

                                 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[i] = data[i];
        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. Re: Variable data length

          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...

          • 2. Re: Variable data length

            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:


                                                 LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_WRITE,

                                                 LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ,  10),



            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



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

            • 3. Re: Variable data length

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


              • 4. Re: Variable data length

                that did it. thank you!