This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to increase the length of characteristic value?

Hi,

I would like to increase the length of read & write characteristic value to 29 bytes. I changed the NRF_SDH_BLE_GAP_DATA_LENGTH = 36 & NRF_SDH_BLE_GATT_MAX_MTU_SIZE = 32. Also changed attr_char_value.max_len  = 29 & ram settings & hvx_params.p_len  = &gatts_value.len. But on nrfconnect I could see only 22 bytes for read characteristic & 2 bytes for write characteristic. What am I missing?

  • Hi, 

    What SDK version and example do you use?

    What is the value of &gatts_value.len?

    Best regards,

    Amanda

  • I'm using ble_app_template example in SDK 15.2. 

    I have set gatts_value.len     = 29*sizeof(uint8_t);

    uint32_t ble_midi_data_io_value_update(ble_midi_service_t * p_midi_service, uint8_t data_io_value[29])
    {
        if (p_midi_service == NULL)
        {
            return NRF_ERROR_NULL;
        }
        uint32_t err_code = NRF_SUCCESS;
        ble_gatts_value_t gatts_value;
        // Initialize value struct.
        memset(&gatts_value, 0, sizeof(gatts_value));
        gatts_value.len     = 29*sizeof(uint8_t);
        gatts_value.offset  = 0;
        gatts_value.p_value = &data_io_value[0];
        // Update database.
        err_code = sd_ble_gatts_value_set(p_midi_service->conn_handle, p_midi_service->data_io_char_handles.value_handle, &gatts_value);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        // Send value if connected and notifying.
        if ((p_midi_service->conn_handle != BLE_CONN_HANDLE_INVALID)) 
        {
            ble_gatts_hvx_params_t hvx_params;
            memset(&hvx_params, 0, sizeof(hvx_params));
            hvx_params.handle = p_midi_service->data_io_char_handles.value_handle;
            hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = gatts_value.offset;
            hvx_params.p_len  = &gatts_value.len;
            hvx_params.p_data = gatts_value.p_value;
            err_code = sd_ble_gatts_hvx(p_midi_service->conn_handle, &hvx_params);
            NRF_LOG_INFO("sd_ble_gatts_hvx result: %x. \r\n", err_code); 
        }
        else
        {
            err_code = NRF_ERROR_INVALID_STATE;
            NRF_LOG_INFO("sd_ble_gatts_hvx result: NRF_ERROR_INVALID_STATE. \r\n"); 
        }
        return err_code;
    }

    Please guide what else do I need to add?

  • Could you provide the code where you initializes the characteristic?

    The code before sd_ble_gatts_characteristic_add ().

    -Amanda

  • /**@brief Function for adding the Data I/O characteristic. */
    static uint32_t data_io_char_add(ble_midi_service_t * p_midi_service, const ble_midi_service_init_t * p_midi_service_init)
    {
        uint32_t   err_code;
        ble_gatts_char_md_t char_md;
        ble_gatts_attr_md_t cccd_md;
        ble_gatts_attr_t    attr_char_value;
        ble_uuid_t          ble_uuid;
        ble_gatts_attr_md_t attr_md;
        // Configure the CCCD which is needed for Notifications and Indications
        memset(&cccd_md, 0, sizeof(cccd_md));
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
        cccd_md.vloc = BLE_GATTS_VLOC_STACK;
        // Configure the characteristic metadata.
        memset(&char_md, 0, sizeof(char_md));
        char_md.char_props.read          = 1;
        char_md.char_props.write_wo_resp = 1;
        char_md.char_props.notify        = 1;
        char_md.p_char_user_desc         = NULL;
        char_md.p_char_pf                = NULL;
        char_md.p_user_desc_md           = NULL;
        char_md.p_cccd_md                = &cccd_md;
        char_md.p_sccd_md                = NULL;
        // Add the MIDI Data I/O Characteristic UUID
        ble_uuid128_t base_uuid = {BLE_UUID_MIDI_DATA_IO_CHAR_BASE_UUID};
        err_code = sd_ble_uuid_vs_add(&base_uuid, &p_midi_service->uuid_type);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        ble_uuid.type = p_midi_service->uuid_type;
        ble_uuid.uuid = BLE_UUID_MIDI_DATA_IO_CHAR_UUID;
        // Configure the characteristic value's metadata
        memset(&attr_md, 0, sizeof(attr_md));
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
        attr_md.vloc       = BLE_GATTS_VLOC_STACK;
        attr_md.rd_auth    = 0;
        attr_md.wr_auth    = 0;
        attr_md.vlen       = 0;
        // Configure the characteristic value
        memset(&attr_char_value, 0, sizeof(attr_char_value));
        attr_char_value.p_uuid       = &ble_uuid;
        attr_char_value.p_attr_md    = &attr_md;
        attr_char_value.init_len     = sizeof(uint8_t);
        attr_char_value.init_offs    = 0;
        attr_char_value.max_len      = 29*sizeof(uint8_t);
        attr_char_value.p_value      = NULL;
        return sd_ble_gatts_characteristic_add(p_midi_service->service_handle, &char_md, &attr_char_value, &p_midi_service->data_io_char_handles);
    }

    I am also attaching the full code for your reference. Please have a look.

    0537.ble_app_template.zip

  • Hi, 

    Change the Line 46 as

        attr_char_value.init_len     = 29*sizeof(uint8_t);

    -Amanda

Related