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 Reply Children
  • Hi Bjorn,

    Thanks for the reply.

    My problem now is on how to get the data from phone to nordic app. I am bit confused on the the message sequence chart.

    If I choose the BLE_GATTS_VLOC_USER, I can see any data on attr_char_value.p_value (I guest it would be there?), and if I choose the BLE_GATTS_VLOC_STACK where could I find the handle, offset and peer values. infocenter.nordicsemi.com/index.jsp

    I also tried to set the NULL and user memory block of sd_ble_user_mem_reply but still I am empty handed.

    Sorry for the confusion, I am still new on BLE development.

    Regards, -mc

  • The handle, offset and value passed to sd_ble_gatts_value_set() are identical to those passed during the ATT Prepare Write Request.

    However, I think I may have referred you to the wrong function if you want to read the characteristic data from a phone using a nordic chip, you should use sd_ble_gattc_read() instead.

  • Hi Bjorn,

    Thank you for following me.

    In this stage, I want to read the 120 bytes that the phone or the MCP for windows writes to the Nordic chip. After I press the Write long from MCP I receive the BLE_EVT_USER_MEM_REQUEST and the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST. Till then, I don't know where to place the sd_ble_gattc_read().

    I tried to place it on the BLE_GATTS_OP_PREP_WRITE_REQ and/or the BLE_GATTS_OP_EXEC_WRITE_REQ_NOW under the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST and MCP will terminate because of BTLE_CONNECTION_TIMEOUT.

    Will you please elaborate further on of how I get the data using as what you suggested.

    Thanks, -mc

  • 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()

  • Hi Bjørn,

    Still I can find any data when executing the sd_ble_gatts_value_get() in the BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST{EXEC_WRITE_NOW}.

    I found some code in long write github.com/.../ble_app_hrs---LongWrite. This does not follow the MSG sequence but I can get the data in BLE_GATTS_EVT_WRITE.

    When trying to update the example HRM code of S310 from the long write examplem, this will follow the MSG but I can't get the data.

    Is there anything I miss to configure to get the the data written to nordic chip.

    Thanks, mc

Related