Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RSSI Change Event & Log not showing

Hi,

I'm developing a simple software that records RSSI values from both the Central and Peripheral device, using nRF5 SDK 15, adapting from two of the provided examples:

ble_app_multipheral for the server/peripheral & ble_app_blinky_c for the client/central.

My issue arose when I was getting a positive value for the RSSI in the server.

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
        {
            on_connected(&p_ble_evt->evt.gap_evt);
        } break;

        case BLE_GAP_EVT_DISCONNECTED:
        {
            on_disconnected(&p_ble_evt->evt.gap_evt);
        } break;
            
        case BLE_GAP_EVT_RSSI_CHANGED:
        {
            NRF_LOG_DEBUG("**RSSI** On RSSI Change Event Received..."); 
            on_rssi_change(&p_ble_evt->evt.gap_evt);
            /*** < To Do: Change from Event to periodic sampling > ***/
        } break;

/**@brief Function for handling the Connected event.
 *
 * @param[in] p_gap_evt GAP event received from the BLE stack.
 */
static void on_connected(const ble_gap_evt_t * const p_gap_evt)
{
    ret_code_t  err_code;
    uint32_t    periph_link_cnt = ble_conn_state_peripheral_conn_count(); // Number of peripheral links.
    uint16_t	conn_handle = p_gap_evt->conn_handle;

    NRF_LOG_INFO("Connection with link 0x%x established.", conn_handle);
    
    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, conn_handle, TX_POWER);
    APP_ERROR_CHECK(err_code);

    // Assign connection handle to available instance of QWR module.
    for (uint32_t i = 0; i < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT; i++)
    {
        if (m_qwr[i].conn_handle == BLE_CONN_HANDLE_INVALID)
        {
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr[i], conn_handle);
            APP_ERROR_CHECK(err_code);
            break;
        }
    }
       
    sd_ble_gap_rssi_start(conn_handle, RSSI_THRESHOLD_DBM, RSSI_SKIP_COUNT); // Enable RSSI Scanning for this connection
    
    ble_pds_assign_handle(&m_pds, conn_handle);
    
    link_led_update(periph_link_cnt);
    
    if (periph_link_cnt == NRF_SDH_BLE_PERIPHERAL_LINK_COUNT) 
        advertising_stop();	// All connections were taken, stop advertising.
    else 
        advertising_start();	// Continue advertising. More connections can be established because the maximum link count has not been reached.
}

/**@brief Function for handling the Changed RSSI event.
 *
 * @param[in] p_gap_evt GAP event received from the BLE stack.
 */
static void on_rssi_change(ble_gap_evt_t const * const p_gap_evt)
{
    ret_code_t  err_code;
    uint16_t	conn_handle = p_gap_evt->conn_handle;

    NRF_LOG_DEBUG("**RSSI** Sent: %d", p_gap_evt->params.rssi_changed.rssi);
    
    ble_pds_send_rssi(conn_handle,
	      &m_pds,
	      p_gap_evt->params.rssi_changed.rssi);
}

Trying to debug this code, I tried using some "NRF_LOG_DEBUG()" functions, they work perfectly everywhere but when a RSSI Changed Event occurs, they don't show on the debug terminal.

I don't understand this behaviour.

As for the information received on the central / client:

It's own RSSI reading is working properly but the information sent by the client is not correct, while debugging with breakpoints this happens (data comes empty):

And when debugging the on_rssi_change function, the ble_event -> gap_event . params . rssi_changed is empty.

I hope I was able to convey my problem clearly.

Thank you in advance for taking your time to help me.

Marco Corrente.

Parents
  • Hi!

    I'm not quite sure why you aren't seeing the output from NRF_LOG_DEBUG().
    I can't see any other debug outputs in the screenshots you uploaded either.
    Are you sure that you have the NRF_LOG_DEFAULT_LEVEL set to debug (level 4) in your sdk_config.h file?

    Also double check that you are receiving the BLE_GAP_EVT_RSSI_CHANGED event?


    As for what you want to acheive here;
    I tried to implement it myself, in the ble_app_multiperipheral/ble_app_blinky_c.
    I didn't do it the exact same way you did, but I had no issue printing the RSSI values on the debug terminal in SES.

    My code;

    /**@brief Function for handling BLE events.
     *
     * @param[in]   p_ble_evt   Bluetooth stack event.
     * @param[in]   p_context   Unused.
     */
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        ret_code_t err_code;
        int8_t rssi;
        uint8_t channel;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                on_connected(&p_ble_evt->evt.gap_evt);
                break;
    
            case BLE_GAP_EVT_DISCONNECTED:
                on_disconnected(&p_ble_evt->evt.gap_evt);
                break;
    
            case BLE_GAP_EVT_RSSI_CHANGED:
    
                err_code = sd_ble_gap_rssi_get (p_ble_evt->evt.gap_evt.conn_handle, &rssi, &channel);
                
                NRF_LOG_DEBUG("RSSI is; %d", rssi); 
                break;

    /**@brief Function for handling the Connected event.
     *
     * @param[in] p_gap_evt GAP event received from the BLE stack.
     */
    static void on_connected(const ble_gap_evt_t * const p_gap_evt)
    {
        ret_code_t  err_code;
        uint32_t    periph_link_cnt = ble_conn_state_peripheral_conn_count(); // Number of peripheral links.
    
        NRF_LOG_INFO("Connection with link 0x%x established.", p_gap_evt->conn_handle);
    
        // Assign connection handle to available instance of QWR module.
        for (uint32_t i = 0; i < NRF_SDH_BLE_PERIPHERAL_LINK_COUNT; i++)
        {
            if (m_qwr[i].conn_handle == BLE_CONN_HANDLE_INVALID)
            {
                err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr[i], p_gap_evt->conn_handle);
                APP_ERROR_CHECK(err_code);
                break;
            }
        }
    
        err_code = app_button_enable();
        APP_ERROR_CHECK(err_code);
    
        sd_ble_gap_rssi_start(p_gap_evt->conn_handle, 5, 0);

    Cheers,
    Joakim.

  • Hi, thanks fort the reply.

    I didn't notice there were various kinds of logs (Debug / Info), changing the log level to 4 solved it, from there it was easy to notice that RSSI variable type was not signed int as should be, hence not showing neg. values.

    It works perfectly now, thank you!

    Marco.

  • I'm glad to hear that!

    Be sure to let us know if you have any other issues.

    Best regards,
    Joakim

Reply Children
No Data
Related