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

RSSI return value - Consistent and Incorrect

Hi,

I am using an NRF 51 DK, SDK 12.3, and Soft Device S130. I am also a beginner to development with Nordic Products, and RSSI collection in general. I am using the ble_peripheral -> ble_app_uart example as a foundation to slowly build upon more and more. Currently, my goal with what I have written is: to send a command via the UART section of the nRF ToolBox app, and print the RSSI value at that given moment on the terminal.

The problem I face, is that no matter what I do, the value that returns is always the same (-112) no matter what I do, as you'll see in my screenshots below. I understand the inconsistency of RSSI, however there should be at the very least some variation. What am I doing wrong?

------------------------------------------------------------------------------------------------------------------------

static void nus_data_handler( ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
    
    // PROGRAMMER COMMENTS:
    // 1 ) handles data received from UART app service
    // 2 ) Code below represents basic BLE communication and RSSI reading
    
    
        uint32_t       err_code; // variable for printing error
        int8_t        p_rssi;   //Pointer to location where RSSI measurement will be stored
    
    
        if (p_data[0] == 'r') { //If first character is 'r'
            
                
                
                    err_code = sd_ble_gap_rssi_start( m_conn_handle, 1 , 1 );
                    
                    if ( err_code != NRF_SUCCESS ) { // If RSSI fails to start scanning
                        printf("Error code: %d\n", err_code);
                        uint8_t data_array[12] = {'a', ' ', 'p', 'r', 'o', 'b', 'l', 'e', 'm', '!', '\n'};
                        uint8_t length_of_data = 12;
                        err_code = ble_nus_string_send(&m_nus, data_array, length_of_data);
                        APP_ERROR_CHECK(err_code);
                    }
                    
                    else {
                        
                        sd_ble_gap_rssi_get( m_conn_handle, &p_rssi );
                        
                        if ( p_rssi < 0 ) {
                            
                                printf("Current RSSI: %d\r\n", p_rssi);

                                sd_ble_gap_rssi_stop( m_conn_handle);
                                err_code = 0; // Re-initializing both variables related to RSSI data collection
                                p_rssi = 0;   // In the hopes of reading out a different RSSI value
                            
                            
                                uint8_t data_array[11] = {'C', 'o', 'n', 'f', 'i', 'r', 'm', 'e', 'd', '!'};
                                uint8_t length_of_data = 11;
                                err_code = ble_nus_string_send(&m_nus, data_array, length_of_data);
                                APP_ERROR_CHECK(err_code);
                                
                                
                        }
                        else { // Should not collect anything greater than 0. Considering it a bad read
                            
                                printf("Error code: %d\n", err_code);
                                printf("Current RSSI: %d\r\n", p_rssi);
                            
                                uint8_t data_array[12] = {'B', 'a', 'd', ' ', 'R', 'e', 'a', 'd', '!', '!', '\n'};
                                uint8_t length_of_data = 12;
                                err_code = ble_nus_string_send(&m_nus, data_array, length_of_data);
                                APP_ERROR_CHECK(err_code);
                        }        
                    }
    }    
        else { // If its not what I want (in this case 'r'), then send it back
                    err_code = ble_nus_string_send(&m_nus,  p_data, length);
                    APP_ERROR_CHECK(err_code);
        }
    
    //for (uint32_t i = 0; i < length; i++)
    //{
        //while (app_uart_put(p_data[i]) != NRF_SUCCESS);
    //}
    //while (app_uart_put('\r') != NRF_SUCCESS);
    //while (app_uart_put('\n') != NRF_SUCCESS);
}

------------------------------------------------------------------------------------------------------------------------

Parents Reply Children
No Data
Related