This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to send more than 4 bytes of data over BLE

Hi,

I am trying to create a custom BLE service.

Following is the main code:

            err_code = ble_cus_flash_update(&m_cus, m_rx_buf, m_conn_handle);
            if (err_code != NRF_SUCCESS &&
                err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
                err_code != NRF_ERROR_INVALID_STATE &&
                err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)

            {
                APP_ERROR_CHECK(err_code);
            }

These are my BLE write functions:

    uint8_t flash_init_value [6] = {0};

    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid              = FLASH_UUID;
    add_char_params.uuid_type         = p_cus->uuid_type;

    add_char_params.init_len          = 6;// (in bytes)
    add_char_params.max_len           = 6;
    add_char_params.p_init_value      = flash_init_value;

    add_char_params.char_props.read   = 1;
    add_char_params.char_props.notify = 1;

    add_char_params.read_access       = SEC_OPEN;
    add_char_params.cccd_write_access = SEC_OPEN;

    err_code = characteristic_add(p_cus->service_handle,
                                  &add_char_params,
                                  &p_cus->flash_handles);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;

uint32_t ble_cus_flash_update(ble_cus_t * p_cus, uint8_t * flash_data_byte, uint16_t conn_handle)
{
    ble_gatts_hvx_params_t params;
    uint16_t len = sizeof(flash_data_byte);

    memset(&params, 0, sizeof(params));
    params.type   = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_cus->flash_handles.value_handle;
    params.p_data = flash_data_byte;
    params.p_len  = &len;

    return sd_ble_gatts_hvx(conn_handle, &params);
}

My sdk_config file says MAX_MTU is defined 23

// <o> NRF_SDH_BLE_GAP_EVENT_LENGTH - GAP event length. 
// <i> The time set aside for this connection on every connection interval in 1.25 ms units.

#ifndef NRF_SDH_BLE_GAP_EVENT_LENGTH
#define NRF_SDH_BLE_GAP_EVENT_LENGTH 6
#endif

// <o> NRF_SDH_BLE_GATT_MAX_MTU_SIZE - Static maximum MTU size. 
#ifndef NRF_SDH_BLE_GATT_MAX_MTU_SIZE
#define NRF_SDH_BLE_GATT_MAX_MTU_SIZE 23
#endif

// <o> NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE - Attribute Table size in bytes. The size must be a multiple of 4. 
#ifndef NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE
#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
#endif

I am using nrf Connect to debug BLE, which gives me output like this:

0x A1-A2-A3-A4-00-00

I am able to send 4 bytes successfully, but the rest of the values are not updating.
Any help would be really appreciated.

Regards,
Anurag

Related