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

RSSI Implementation with nRF52480 on BLE UART APK

Hi,

I'm testing the ble_app_uart and ble_app_uart_c example on two nRF52480 cards.

I'm actually trying to print the RSSI value.

I don't really know how to proceed to start the RSSI measurement and where I should call the function and print the new RSSI value if this value changed.

I'm using 14.2 SDK from Nordic but I guess it's nearly the same with other SDK.

Thanks in advance for your help, please don't hesitate to ask for specifics.

OP

  • Hi,

    You have to call sd_ble_gap_rssi_start() initially so that the SoftDevice will start to report the RSSI. Depending on the parameters, you will get an event every time the RSSI change or if it changes beyond a given threshold. You can also poll by calling sd_ble_gap_rssi_get(). These message sequence charts shows all variants:

    As a side note, it seems you use the nRF52840 with DK 14.2. Please note that it is not recommended to use SDK 14.2 with the nRF52840. It was only supported experimentally. SDK 15.0.0 was the first SDK release with production quality support for the nRF52840.

  • Thanks a lot for your anser Einar,

    I added theses lines to the example code in the ble_evt_handler function in main.c.

      case BLE_GAP_EVT_CONNECTED:
                printf("Connected!\r\n!");
    						
                NRF_LOG_INFO("Connected to target");
                err_code = ble_nus_c_handles_assign(&m_ble_nus_c, p_ble_evt->evt.gap_evt.conn_handle, NULL);
                sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle, 1, 1); //added by _OP
    						printf("It does pass by sd_ble_gap_rssi_start\n");
    						APP_ERROR_CHECK(err_code);
                err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                APP_ERROR_CHECK(err_code);
                // start discovery of services. The NUS Client waits for a discovery result
                err_code = ble_db_discovery_start(&m_db_disc, p_ble_evt->evt.gap_evt.conn_handle);
                APP_ERROR_CHECK(err_code);
                break;
    				
    				case BLE_GAP_EVT_RSSI_CHANGED:          //block added by _OP
    						sd_ble_gap_rssi_get(p_ble_evt->evt.gap_evt.conn_handle, &RSSI);
    						NRF_LOG_INFO("rssi =%d dBm",	RSSI);
    						break;
    						
            case BLE_GAP_EVT_TIMEOUT:
                if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_SCAN)
                {
                    NRF_LOG_INFO("Scan timed out.");
                    scan_start();
                }
                else if (p_gap_evt->params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
                {
                    NRF_LOG_INFO("Connection Request timed out.");
                }
                break;
     

    it does pass by the sd_ble_gap_rssi_start function but not by the BLE_GAP_EVT_RSSI_CHANGED event

    I'm on 14.2 SDK because i'm testing the long range app and it's not compatible with 15 (doesn't compile).

    Thanks in advance.

    _OP

  • Hi,

    That's odd. It should work. In fact I copy-pasted your code into an SDK 14.2 example and it worked out of the box (I just had to declare your RSSI variable as int8_t). Have you verified by a debugger that you get the BLE_GAP_EVT_CONNECTED event (and thus call sd_ble_gap_rssi_start()), but you still don't get any BLE_GAP_EVT_RSSI_CHANGED events? Are there any other events instead (particularly BLE_GAP_EVT_DISCONNECTED, which would explain why you don't get any RSSI measurements)?

  • Thanks for your quick anser.

    Indeed i don't get the 'disconected'  msg from the BLE_GAP_EVT_DISCONNECTED event when i turn down the second card.

    i'm using putty the output i'm getting is below:

    So the sd_ble_gap_rssi_start() is called but the condition "case BLE_GAP_EVT_RSSI_CHANGED:" isn't ever valide (even if i move the cards.. i don't get the msg one single time).

    how shoud i fix it ? Is it a good idea to use putty to debug ? Can i see your output with your debugger ?

    Thx again Einar.

  • Hi,

    I did this modifications to the HRS example main.c file from SDK 14.2:

    diff --git a/examples/ble_peripheral/ble_app_hrs/main.c b/examples/ble_peripheral/ble_app_hrs/main.c
    index 1c0f4a8..43cc070 100644
    --- a/examples/ble_peripheral/ble_app_hrs/main.c
    +++ b/examples/ble_peripheral/ble_app_hrs/main.c
    @@ -760,6 +760,7 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
     static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
     {
         ret_code_t err_code;
    +    int8_t rssi;
     
         switch (p_ble_evt->header.evt_id)
         {
    @@ -768,6 +769,13 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
                 err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                 APP_ERROR_CHECK(err_code);
                 m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    +            err_code = sd_ble_gap_rssi_start(m_conn_handle, 1, 1);
    +            APP_ERROR_CHECK(err_code);
    +            break;
    +
    +        case BLE_GAP_EVT_RSSI_CHANGED:          //block added by _OP
    +            sd_ble_gap_rssi_get(p_ble_evt->evt.gap_evt.conn_handle, &rssi);
    +            NRF_LOG_INFO("rssi =%d dBm", rssi);
                 break;
     
             case BLE_GAP_EVT_DISCONNECTED:
    

    This resulted in the following log output (RSSI measurements are printed for as long as the connection is alive):

    <info> app: Heart Rate Sensor example started.
    <info> app: Fast advertising.
    <info> app: Connected.
    <info> app: rssi =-56 dBm
    <info> app: rssi =-47 dBm
    <info> app: rssi =-57 dBm
    <info> app: rssi =-54 dBm
    <info> app: rssi =-50 dBm
    <info> app: GATT ATT MTU on connection 0x0 changed to 247.
    <info> app: rssi =-49 dBm
    <info> app: rssi =-47 dBm
    <info> app: rssi =-50 dBm
    <info> app: rssi =-54 dBm
    <info> app: rssi =-51 dBm
    <info> app: rssi =-50 dBm
    <info> app: rssi =-46 dBm
    <info> app: rssi =-49 dBm
    <info> app: rssi =-54 dBm
    <info> app: rssi =-53 dBm
    <info> app: rssi =-50 dBm
    <info> app: rssi =-53 dBm
    <info> app: rssi =-48 dBm
    <info> app: rssi =-49 dBm
    <info> app: rssi =-46 dBm
    <info> app: rssi =-51 dBm
    <info> app: rssi =-54 dBm
    <info> app: rssi =-51 dBm
    <info> app: rssi =-49 dBm
    <info> app: rssi =-47 dBm
    <info> app: rssi =-51 dBm
    <info> app: rssi =-54 dBm
    <info> app: rssi =-51 dBm
    <info> app: rssi =-49 dBm
    

    You should get the same. Does your application work as expected without the RSSI logging?

Related