Hi there! I found out that there is some problem in the example ble_app_hrs_rscs_relay in nRF5_SDK_11.0.0_89a8197. I want to restart advertising when adv timeout. I did as follow:
static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
switch (ble_adv_evt)
{
case BLE_ADV_EVT_FAST:
LEDS_ON(PERIPHERAL_ADVERTISING_LED);
break;
case BLE_ADV_EVT_IDLE:
ret_code_t err_code;
LOG(LEVEL_INFO, "Restart adv\r\n");
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
break;
default:
break;
}
}
but it did not call this function when timeout ! and then I checked this function :
static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
uint16_t conn_handle;
uint16_t role;
ble_conn_state_on_ble_evt(p_ble_evt);
pm_on_ble_evt(p_ble_evt);
// The connection handle should really be retrievable for any event type.
conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
role = ble_conn_state_role(conn_handle);
LOG(LEVEL_WARNING, " role:%d\t evt :%d\r\n", role, p_ble_evt->header.evt_id);
// Based on the role this device plays in the connection, dispatch to the right applications.
if (role == BLE_GAP_ROLE_PERIPH)
{
LOG(LEVEL_WARNING, " peripheral evt \r\n");
// Manages peripheral LEDs.
on_ble_peripheral_evt(p_ble_evt);
ble_advertising_on_ble_evt(p_ble_evt);
ble_conn_params_on_ble_evt(p_ble_evt);
ble_nus_on_ble_evt(&m_nus, p_ble_evt);
}
else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT))
{
/** on_ble_central_evt will update the connection handles, so we want to execute it
* after dispatching to the central applications upon disconnection. */
if (p_ble_evt->header.evt_id != BLE_GAP_EVT_DISCONNECTED)
{
on_ble_central_evt(p_ble_evt);
}
if (conn_handle < CENTRAL_LINK_COUNT + PERIPHERAL_LINK_COUNT)
{
ble_db_discovery_on_ble_evt(&m_ble_db_discovery[conn_handle], p_ble_evt);
}
ble_nus_c_on_ble_evt(&m_ble_nus_c,p_ble_evt);
// If the peer disconnected, we update the connection handles last.
if (p_ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)
{
on_ble_central_evt(p_ble_evt);
}
}
}
I used LOG to output the value of role and evt_id, when adv timeout, it output: role:0 (equals to BLE_GAP_ROLE_INVALID) evt :27 (equals to BLE_GAP_EVT_TIMEOUT) I think role should be BLE_GAP_ROLE_PERIPH when advertise, but:
conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
role = ble_conn_state_role(conn_handle);
before establish a connection, role equals BLE_GAP_ROLE_INVALID all the time. So I think it is not right to call function ble_advertising_on_ble_evt(p_ble_evt); in
if (role == BLE_GAP_ROLE_PERIPH)
{
ble_advertising_on_ble_evt(p_ble_evt);
}
it makes no sense when adv timeout evt comes. now I call this function when role equals BLE_GAP_ROLE_INVALID , and it does work. Am I right? can anyone help me? Thank you very much!