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

Connection mode and custom service

Hi, I want to make a connectable bluettoth transmission. I need 1 service with 3 characteristics, but for now I only want to see my service in app. It is possible to do it without events? Now i send advertising and i can connect to my device.I use for it NRF Control Master on Android.I cant see any services.The status in application is still Discovering services.

This is my code: Service function:

uint32_t battery_char_add(my_serv * my_serv_struct) {

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.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 = my_serv_struct->uuid_type;
ble_uuid.uuid = UUID_BATTERY_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(my_serv_struct->service_handle, &char_md,
                                           &attr_char_value,
                                           &my_serv_struct->battery_char_handles);

}

uint32_t ble_serv_init(my_serv * my_serv_struct){

uint32_t   err_code;
ble_uuid_t ble_uuid;

ble_uuid128_t base_uuid = {MY_UUID_BASE};
err_code = sd_ble_uuid_vs_add(&base_uuid, &my_serv_struct->uuid_type);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}
ble_uuid.type = my_serv_struct->uuid_type;
ble_uuid.uuid = MY_UUID_SERVICE;

err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &my_serv_struct->service_handle);
	 if (err_code != NRF_SUCCESS)
{
    return err_code;
} 
err_code = battery_char_add(my_serv_struct);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}


return NRF_SUCCESS;

}

Advertising:

void advertising_init(void)

{ uint32_t err_code; uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

ble_advdata_manuf_data_t manuf_specific_data;

manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
manuf_specific_data.data.p_data = (uint8_t *) MY_DATA;
manuf_specific_data.data.size   = 9;

// Build and set advertising data.
memset(&advdata, 0, sizeof(advdata));

advdata.name_type             = BLE_ADVDATA_SHORT_NAME;
	advdata.include_appearance      = true;
	advdata.short_name_len = 6;
advdata.flags                 = flags;
	
advdata.p_manuf_specific_data = &manuf_specific_data;

err_code = ble_advdata_set(&advdata, NULL);
APP_ERROR_CHECK(err_code);

// Initialize advertising parameters (used when starting advertising).
memset(&m_adv_params, 0, sizeof(m_adv_params));

m_adv_params.type   = BLE_GAP_ADV_TYPE_ADV_IND;
m_adv_params.p_peer_addr = NULL;
m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval    = APP_ADV_INTERVAL;
m_adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;

} GAP params:

void gap_params_init(void) { uint32_t err_code; ble_gap_conn_params_t gap_conn_params; ble_gap_conn_sec_mode_t sec_mode;

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err_code = sd_ble_gap_device_name_set(&sec_mode,(const uint8_t *)DEVICE_NAME,strlen(DEVICE_NAME));
APP_ERROR_CHECK(err_code);

  gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
gap_conn_params.slave_latency     = SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;

err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);

}

MAIN: int main(void){ uint32_t err_code; ble_stack_init(); gap_params_init(); ble_serv_init(&my_serv_struct);

advertising_init(); advertising_start();

} I use sd110 and sdk 8.0 My project:BLE.7z

Any sugestions?

Parents
  • Should work. Difficult to say what is happening though. Could you test on Master Control Panel for PC? Or maybe sniff the connection with nRF Sniffer to see what is happening? Or, would it be possible to update your question with your complete project together with SoftDevice version and SDK version? If it is private you can also make case in your MyPage and upload it there.

Reply
  • Should work. Difficult to say what is happening though. Could you test on Master Control Panel for PC? Or maybe sniff the connection with nRF Sniffer to see what is happening? Or, would it be possible to update your question with your complete project together with SoftDevice version and SDK version? If it is private you can also make case in your MyPage and upload it there.

Children
No Data
Related