I am a beginner developer.
I am working on ble_app_multilink_central and ble_app_uart-based projects and succeeded in BLE multi-connecting. But there is a problem. An error occurs in the BLE connection. In my project, when the device names of central and peripheral match, sd_ble_gap_connect is executed to establish a BLE connection between devices. However, even though the device name between the two devices is different, it sometimes becomes a BLE connection. It's not always like that, so I'm very frustrated. So I want to check the device name of peripheral in central.
I think the solution may be related to "static void on_adv_report (ble_gap_evt_adv_report_t const * p_adv_report)".
This is my code..
static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
{
ret_code_t err_code;
if ( ble_advdata_name_find(p_adv_report->data.p_data, p_adv_report->data.len, m_target_periph_name) || ble_advdata_name_find(p_adv_report->data.p_data, p_adv_report->data.len, DEVICE_NAME))
{
scan_stop();
// Name is a match, initiate connection.
err_code = sd_ble_gap_connect(&p_adv_report->peer_addr,
&m_scan_params,
&m_connection_param,
APP_BLE_CONN_CFG_TAG);
if (err_code != NRF_SUCCESS)
{
#ifdef DEBUG
NRF_LOG_ERROR("Connection Request Failed, reason %d", err_code);
#endif
}
#ifdef DEBUG
NRF_LOG_ERROR("Connection Request Failed, reason %d", err_code);
#endif
}
}
And I checked 'bool ble_advdata_name_find' at C:\Users\Root\Desktop\nordic_15.2\components\ble\common\ble_advdata.c
bool ble_advdata_name_find(uint8_t const * p_encoded_data,
uint16_t data_len,
char const * p_target_name)
{
uint16_t parsed_name_len;
uint8_t const * p_parsed_name;
uint16_t data_offset = 0;
if (p_target_name == NULL)
{
return false;
}
parsed_name_len = ble_advdata_search(p_encoded_data,
data_len,
&data_offset,
BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
p_parsed_name = &p_encoded_data[data_offset];
if ( (data_offset != 0)
&& (parsed_name_len != 0)
&& (strlen(p_target_name) == parsed_name_len)
&& (memcmp(p_target_name, p_parsed_name, parsed_name_len) == 0))
{
return true;
}
return false;
}
That's all I found out.
I want to debug the device name that peripheral advertises.
Please help me solve this problem. T^T