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

ble_ant_app_hrm not find ble services

Dears,

I have a problem with the ble_ant_app_hrm in the examples (multiprotocol). I am using a pca10040 demo board with sdk 14.2 with IDE SES on a MacOS

I have flash the softdevice s332, compile and run the example.

I can discover the device by bluetooth on the NRF connect app but when I want to connect it is continuously saying that it is « connecting » and the led0 on the board is continually ON.

I have done a small app by my own on iOS, I can connect with a heart rate belt from Decathlon and when I try to connect with the pca10040 board it discovers it but never received a response after discovering services.

I have seen in the code that there is a BONDING_ENABLE macro,

I have add a line:

#define BONDING_ENABLE

At the beginning of the main.c

But I have the error by compiling

Building ‘ble_ant_app_hrm_pca10040_s332’ from solution ‘ble_ant_app_hrm_pca10040_s332’ in configuration ‘Debug’

  Compiling ‘main.c’

    implicit declaration of function 'fs_sys_event_handler'; did you mean 'soc_evt_handler'? [-Wimplicit-function-declaration]

    implicit declaration of function 'ble_advertising_on_sys_evt'; did you mean 'advertising_init'? [-Wimplicit-function-declaration]

    expected ')' before numeric constant

    implicit declaration of function 'NRF_LOG_INFO_DEBUG'; did you mean 'NRF_LOG_DEBUG'? [-Wimplicit-function-declaration]

Build failed

Corresponding to:

static void soc_evt_handler(uint32_t evt_id, void * p_context)

{

    // Dispatch the system event to the fstorage module, where it will be

    // dispatched to the Flash Data Storage (FDS) module.

    fs_sys_event_handler(evt_id);

    // Dispatch to the Advertising module last, since it will check if there are any

    // pending flash operations in fstorage. Let fstorage process system events first,

    // so that it can report correctly to the Advertising module.

    ble_advertising_on_sys_evt(evt_id);

}

NRF_SDH_SOC_OBSERVER_REGISTER(m_soc_observer, 0, soc_evt_handler, NULL);

Am I doing something wrong? Any idea why it is stucking at the discovery of the services?

Thank you!

  • Hi, 

    It does not seem like the code has been tested with the BONDING_ENABLE flag, which is unfortunate. Following changes should fix the problems:

    diff --git a/components/libraries/util/app_error_weak.c b/components/libraries/util/app_error_weak.c
    index f00b36f..4b050b8 100644
    --- a/components/libraries/util/app_error_weak.c
    +++ b/components/libraries/util/app_error_weak.c
    @@ -94,7 +94,7 @@ __WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
         }
     #endif
     
    -    NRF_BREAKPOINT_COND;
    +    //NRF_BREAKPOINT_COND;
         // On assert, the system can only recover with a reset.
     
     #ifndef DEBUG
    diff --git a/examples/multiprotocol/ble_ant_app_hrm/main.c b/examples/multiprotocol/ble_ant_app_hrm/main.c
    index 90ac07b..23b3f9a 100644
    --- a/examples/multiprotocol/ble_ant_app_hrm/main.c
    +++ b/examples/multiprotocol/ble_ant_app_hrm/main.c
    @@ -99,6 +99,10 @@
     #include "nrf_log_ctrl.h"
     #include "nrf_log_default_backends.h"
     
    +#include "ble_advertising.h"
    +
    +#define BONDING_ENABLE
    +
     #define WAKEUP_BUTTON_ID                0                                            /**< Button used to wake up the application. */
     #define BOND_DELETE_ALL_BUTTON_ID       1                                            /**< Button used for deleting all bonded centrals during startup. */
     
    @@ -140,7 +144,8 @@
     static volatile uint16_t                m_conn_handle = BLE_CONN_HANDLE_INVALID;     /**< Handle of the current connection. */
     static ble_gap_adv_params_t             m_adv_params;                                /**< Parameters to be passed to the stack when starting advertising. */
     BLE_HRS_DEF(m_hrs);                                                                  /**< Heart rate service instance. */
    -
    +BLE_ADVERTISING_DEF(m_advertising);                                                  /**< Advertising module instance. */
    +NRF_BLE_GATT_DEF(m_gatt);                                                            /**< GATT module instance. */      
     ant_hrm_profile_t m_ant_hrm;                                                         /**< ANT HRM profile instance. */
     HRM_DISP_CHANNEL_CONFIG_DEF(m_ant_hrm,
                                 ANT_HRMRX_ANT_CHANNEL,
    @@ -540,25 +545,6 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
     }
     
     #ifdef BONDING_ENABLE
    -/**
    - * @brief SoftDevice SoC event handler.
    - *
    - * @param[in] evt_id    SoC event.
    - * @param[in] p_context Context.
    - */
    -static void soc_evt_handler(uint32_t evt_id, void * p_context)
    -{
    -    // Dispatch the system event to the fstorage module, where it will be
    -    // dispatched to the Flash Data Storage (FDS) module.
    -    fs_sys_event_handler(evt_id);
    -
    -    // Dispatch to the Advertising module last, since it will check if there are any
    -    // pending flash operations in fstorage. Let fstorage process system events first,
    -    // so that it can report correctly to the Advertising module.
    -    ble_advertising_on_sys_evt(evt_id);
    -}
    -
    -NRF_SDH_SOC_OBSERVER_REGISTER(m_soc_observer, 0, soc_evt_handler, NULL);
     
     
     /**@brief Function for handling Peer Manager events.
    @@ -584,7 +570,7 @@ static void pm_evt_handler(pm_evt_t const * p_evt)
                 break; // PM_EVT_CONN_SEC_START
     
             case PM_EVT_CONN_SEC_SUCCEEDED:
    -            NRF_LOG_INFO_DEBUG("Link secured. Role: %d. conn_handle: %d, Procedure: %d",
    +            NRF_LOG_DEBUG("Link secured. Role: %d. conn_handle: %d, Procedure: %d",
                                      ble_conn_state_role(p_evt->conn_handle),
                                      p_evt->conn_handle,
                                      p_evt->params.conn_sec_succeeded.procedure);
    @@ -754,6 +740,28 @@ static void softdevice_setup(void)
         NRF_SDH_ANT_OBSERVER(m_ant_observer, APP_ANT_OBSERVER_PRIO, ant_evt_handler, NULL);
     }
     
    +/**@brief GATT module event handler.
    + */
    +static void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
    +{
    +    if (p_evt->evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED)
    +    {
    +        NRF_LOG_INFO("GATT ATT MTU on connection 0x%x changed to %d.",
    +                     p_evt->conn_handle,
    +                     p_evt->params.att_mtu_effective);
    +    }
    +
    +    ble_hrs_on_gatt_evt(&m_hrs, p_evt);
    +}
    +
    +
    +/**@brief Function for initializing the GATT module.
    + */
    +static void gatt_init(void)
    +{
    +    ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, gatt_evt_handler);
    +    APP_ERROR_CHECK(err_code);
    +}
     
     /**@brief Application main function.
      */
    @@ -779,6 +787,10 @@ int main(void)
     
         // Initialize Bluetooth stack parameters.
         gap_params_init();
    +    /*GATT module is used to handle MTU and Data length requests from peer device.
    +      Link will be terminated (after 30 s) if the application does not respond to 
    +      these requests*/
    +    gatt_init();
         advertising_init();
         services_init();
         conn_params_init();
    @@ -790,7 +802,7 @@ int main(void)
         APP_ERROR_CHECK(err_code);
     
     #ifdef BONDING_ENABLE
    -    bool erase_bonds = bsp_button_is_pressed(BSP_BUTTON_1);
    +    bool erase_bonds = bsp_button_is_pressed(BOND_DELETE_ALL_BUTTON_ID);
     
         peer_manager_init(erase_bonds);
         if (erase_bonds == true)
    


    Am I doing something wrong? Any idea why it is stucking at the discovery of the services?

    You are not doing anything wrong; it's the example that is not set up correctly. Service discovery fails because the application doesn't handle MTU and DLE requests from the central. I enabled the GATT module to fix this, see diff above. 

Related