Hi all,
I have a small question. If a GATT server needs to send data to a GATT client(about 65 bytes), does it have to create a service first and then adds characteristic, or it can use directly sd_gap_gatts_hvx function()?
Regards,
mohBOSS.
Hi there,
You will need to add a service and a characteristic to send arbitrary data. Once you have the handle to the characteristic you can use sd_ble_gatts_hvx() to send data. Alternatively, if it's easier for you, you can add the service and characteristic on the peer device and use sd_ble_gattc_write() to send data, acting as a GATT client.
Carles
Hi Carles,
In fact I need to be a server, in order to send data to the client. I can not understand yet how to make a service that can be used by the client to read data. So far I have adapted this code for my needs.
static uint32_t characteristic_add(ble_lbs_t * p_lbs) { 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.char_props.read = 1;
char_md.char_props.write = 1;
char_md.char_ext_props.reliable_wr = 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 = LBS_UUID_LED_CHAR;
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 = 1;
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 = 30;
attr_char_value.p_value = NULL;
return sd_ble_gatts_characteristic_add(p_lbs->service_handle, &char_md,
&attr_char_value,
&p_lbs->led_char_handles);
}
But I can't replace the ble_lbs_t type with what I need.
I hope You are understanding me Dear Carles.
Hi there,
Not sure about ble_lbs_t, it's not something that's part of the SoftDevice. What I would recommend for simple data transmission as a service is to take a look at:
Service: components/ble/ble_services/ble_nus
Example using the service: examples/ble_peripheral/ble_app_uart
The function call to: ble_nus_string_send()
is what you need. It sends a notification with arbitrary data.
Carles
Hi, please I have some questions.
I hope that you understand me. Thanks a lot.
mohBOSS.
Hi there,
Carles