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

How could Nordic received large byte from phone

Hi there,

How could I receive a large data from phone, example 120 bytes from a characteristic. So far I was able to receive 20 bytes.

From the working code of 20 bytes, I modified it so that it would receive a maximum data of sizeof(uint8_t) and change the location from stack to user(BLE_GATTS_VLOC_USER) but its not working. It seems that i haven't receive anything from the BLE GATT WRITE EVENT.

If Characteristic wont able to received a large amount of data, will you please tell me on how to transfer a large amount of data to Nordic.

I am using S310 softdevice and nRF51422 chip. Thanks

below is my code.

static uint32_t add_char_command_type(ble_myplbs * p_lbs, const ble_lbs_init_t * p_lbs_init) { ble_gatts_char_md_t char_md; ble_gatts_attr_t attr_char_value; ble_uuid_t ble_uuid; ble_gatts_attr_md_t attr_md;

memset(&char_md, 0, sizeof(char_md));

char_md.p_char_user_desc = (uint8_t *)CHAR_NAME_COMMAND_TYPE;
char_md.char_user_desc_max_size = 12;
char_md.char_user_desc_size = 12;
	
char_md.char_props.read   = 1; 
char_md.char_props.write  = 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         = NULL;
char_md.p_sccd_md         = NULL;

ble_uuid.type = p_lbs->uuid_type;
ble_uuid.uuid = SAL_UUID_CHAR_COMMAND_TYPE;

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_USER; 
attr_md.rd_auth    = 0;
attr_md.wr_auth    = 0;
attr_md.vlen       = 0;

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      = sizeof(uint8_t); 
attr_char_value.p_value      = ble_buffer_write; 

return sd_ble_gatts_characteristic_add(p_lbs->service_handle, &char_md,
                                           &attr_char_value,
                                           &p_lbs->command_type_char_handle);
Parents
  • You can use long writes to write to characteristics that are larger than 20 bytes, please see this post and the documentation of sd_ble_gattc_write

    This Message Sequence Chart(MSG) may also be helpful.

    -Bjørn

    UPDATE:

    Modified version of SDK v9.0 where the ble_app_hrs example has been modified to support long writes to the heart rate measurement characteristic.

    nRF51_SDK_v9_0.zip

  • Oh, I am sorry, I thought that you wanted the peripheral to either read/write to a characteristic not the other way around. Disregard what I have been writting about sd_ble_gattc_write and sd_ble_gattc_read. It is pretty much as shown in the MSC: When the phone or MCP performs a long write to the characteristic where you want to store the data, you will get the BLE_EVT_USER_MEM_REQUEST event from the SD, to which you reply sd_ble_user_mem_reply(). After replying you will get the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST{PREP_WRITE_REQ} event, to which you reply using sd_ble_gatts_rw_authorize_reply() . Then you will get the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST{EXEC_WRITE_NOW} to which you reply sd_ble_gatts_value_set(). The value is now in your Attribute table and can be retrieved using sd_ble_gatts_value_get()

Reply
  • Oh, I am sorry, I thought that you wanted the peripheral to either read/write to a characteristic not the other way around. Disregard what I have been writting about sd_ble_gattc_write and sd_ble_gattc_read. It is pretty much as shown in the MSC: When the phone or MCP performs a long write to the characteristic where you want to store the data, you will get the BLE_EVT_USER_MEM_REQUEST event from the SD, to which you reply sd_ble_user_mem_reply(). After replying you will get the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST{PREP_WRITE_REQ} event, to which you reply using sd_ble_gatts_rw_authorize_reply() . Then you will get the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST{EXEC_WRITE_NOW} to which you reply sd_ble_gatts_value_set(). The value is now in your Attribute table and can be retrieved using sd_ble_gatts_value_get()

Children
No Data
Related