Hello
I am using Android and BLE communication with nRF52832 (BLENano2) now.
I am using SDK 15.0.0 with keil uversion.
Central is Android and peripheral is nRF52832.
Use the SDK "app_ble_blinky"
I want to make the value of the accelerometer connected to BLENano2 be able to be viewed on Central Android by BLE communication.
So I made the following statement to add a characteristic.
(ble_lbs.h)
#define UUID_VALUE_CHAR 0x1526
(ble_lbs.c)
static uint32_t sensor_char_add(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
{
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;
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;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 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;
ble_uuid.type = p_lbs->uuid_type;
ble_uuid.uuid = UUID_VALUE_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_NO_ACCESS(&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;
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 = NULL;
return sd_ble_gatts_characteristic_add(p_lbs->service_handle,
&char_md,
&attr_char_value,
&p_lbs->button_char_handles);
}
(ble_lbs.c)
uint32_t ble_lbs_init(ble_lbs_t * p_lbs, const ble_lbs_init_t * p_lbs_init)
{
uint32_t err_code;
ble_uuid_t ble_uuid;
// Initialize service structure.
p_lbs->led_write_handler = p_lbs_init->led_write_handler;
// Add service.
ble_uuid128_t base_uuid = {LBS_UUID_BASE};
err_code = sd_ble_uuid_vs_add(&base_uuid, &p_lbs->uuid_type);
VERIFY_SUCCESS(err_code);
ble_uuid.type = p_lbs->uuid_type;
ble_uuid.uuid = LBS_UUID_SERVICE;
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_lbs->service_handle);
VERIFY_SUCCESS(err_code);
// Add characteristics.
err_code = button_char_add(p_lbs, p_lbs_init);
VERIFY_SUCCESS(err_code);
err_code = led_char_add(p_lbs, p_lbs_init);
VERIFY_SUCCESS(err_code);
err_code = sensor_char_add(p_lbs, p_lbs_init);////////add
VERIFY_SUCCESS(err_code);/////////////////////////////add
return NRF_SUCCESS;
}
I defined a UUID, wrote an additional feature of the characteristic, and called it in ble_lbs_init.
However, as a result, scanning with the nRFConnect app confirmed the existing "LED characteristic" and "BUTTON catacteristic" but did not display the added characteristic.
Is there anything else to set up?Please tell me if there is a person who understands.
Or you can change the "Button characteristic" operation instead of adding a characteristic.
I want to send values at regular intervals regardless of the button status, not sending the status when the button is pressed.
Thank you!