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

regarding the distance for the bluetooth range for scan and advertisement for nrf52840

Hi Nordic,

I am using the two nrf52840 units to test adv and scanning in a pair for the development. I am using BLE_GAP_PHY_CODED for both scan and advertisement. But when I test it, seems the package lost get very high when distance is longer than 70 meters. Any way to improve it? Also, is it possible to use the antenna signal amplifer for improve the receiving and advertisement distance?

Parents Reply Children
  • Thank you for your reply. I have tested a bit on your suggestion for the BLE uart example with both Peripheral  and Central side with long distance setup as you suggested. But the distance test result still around 280meters in the open area. 

    Any suggestions to me?

    Peripheral side code is shown below 

    static void advertising_init(void)
    {
        ret_code_t             err_code;
        int8_t tx_power = 8; 
        ble_advertising_init_t init;
        memset(&init, 0, sizeof(init));
        init.advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance      = false;
        init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
        init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.advdata.uuids_complete.p_uuids  = m_adv_uuids;
        init.config.ble_adv_fast_enabled      = true;
        init.config.ble_adv_fast_interval     = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout      = APP_ADV_DURATION;
    
         init.config.ble_adv_primary_phy       = BLE_GAP_PHY_CODED;
         init.config.ble_adv_secondary_phy     = BLE_GAP_PHY_CODED;
         init.config.ble_adv_extended_enabled  = true; 
     
        init.evt_handler = on_adv_evt;
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    
        err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV , m_advertising.adv_handle, tx_power);
        APP_ERROR_CHECK(err_code);
    }
    
    
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t err_code;
    	int8_t tx_power = 8; //niklas
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                //NRF_LOG_INFO("Connected"); 
    	    status=1;
    	    status_connected=1;
                
                #ifdef UART_LOG_ENABLE1
                printf("Connect");nrf_delay_ms(1);
                #endif
                
                //interrupt_pin_init();//niklas
                err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                APP_ERROR_CHECK(err_code);
                //reference https://jimmywongiot.com/2019/11/30/how-to-get-the-rssi-change-on-the-nrf5-sdk/
                //https://devzone.nordicsemi.com/f/nordic-q-a/69366/regarding-about-the-connection-rssi-for-signal-strength
                err_code = sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle,1,2);//niklas
                APP_ERROR_CHECK(err_code);
    
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
                APP_ERROR_CHECK(err_code);
    	    //err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, m_conn_handle, tx_power); //niklas
    	    //APP_ERROR_CHECK(err_code);
                ble_connect_fg = 1;
                break;
    
            //case BLE_GAP_EVT_RSSI_CHANGED:
            //     rssi_value=p_ble_evt->evt.gap_evt.params.rssi_changed.rssi;
            //     printf("RSSI=%d\n",p_ble_evt->evt.gap_evt.params.rssi_changed.rssi);
    
            case BLE_GAP_EVT_DISCONNECTED:
    	    status=2;
    	    status_connected=2;
                NRF_LOG_INFO("Disconnected");
    	    
                #ifdef UART_LOG_ENABLE
                printf("Disc");nrf_delay_ms(1);
                #endif
                //interrupt_pin_init();//niklas
    			
                // LED indication will be changed when advertising starts.
                m_conn_handle = BLE_CONN_HANDLE_INVALID;
    
    			if(nrf_gpio_pin_read(PIN_INTERRUPT))
    			{ 
    			 printf("In AA");nrf_delay_ms(1);
    			 //in_pin_handler();
    			}
                //advertising_start();
                ble_connect_fg = 0;
                break;
    
            case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
            {
                status=3;
                //NRF_LOG_DEBUG("PHY update request.");
                printf("PHY update request.");nrf_delay_ms(1);
                
                ble_gap_phys_t const phys =
                {
    
                    .rx_phys = BLE_GAP_PHY_CODED,//BLE_GAP_PHY_AUTO,
                    .tx_phys = BLE_GAP_PHY_CODED,//BLE_GAP_PHY_AUTO,
    
    
    
                };
                err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
                APP_ERROR_CHECK(err_code);
            } break;
    
            case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
    		     status=5;
                // Pairing not supported
                err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_SYS_ATTR_MISSING:
    		    status=6;
                // No system attributes have been stored.
                err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTC_EVT_TIMEOUT:
                // Disconnect on GATT Client timeout event.
    			status=7;
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            case BLE_GATTS_EVT_TIMEOUT:
    		    status=8;
                // Disconnect on GATT Server timeout event.
                err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                APP_ERROR_CHECK(err_code);
                break;
    
            default:
    		    status=9;
                // No implementation needed.
                break;
        }
    }
    
    int main(void)
    {
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
    

    The central side code is below also 

    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.p_scan_param = &m_scan_params;
        init_scan.connect_if_match = true;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
        APP_ERROR_CHECK(err_code);
    
        // Setting filters for scanning.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
    
    }
    
    
    
    int main(void)
    {
        // Initialize.
        log_init();
        timer_init();
        uart_init();
        buttons_leds_init();
        db_discovery_init();
        power_management_init();
        ble_stack_init();
        gatt_init();
        nus_c_init();
        scan_init();
    

    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.p_scan_param = &m_scan_params;
        init_scan.connect_if_match = true;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
        APP_ERROR_CHECK(err_code);
    
        // Setting filters for scanning.
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
    
    }
    
    static void scan_start(void)
    {
        ret_code_t ret;
    
    
        ret = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, BLE_CONN_HANDLE_INVALID, 8);
        APP_ERROR_CHECK(ret);
        
        ret = nrf_ble_scan_start(&m_scan);
        //ret = sd_ble_gap_scan_start(&m_scan_params, &m_scan_buffer);
        APP_ERROR_CHECK(ret);
    
        ret = bsp_indication_set(BSP_INDICATE_SCANNING);
        APP_ERROR_CHECK(ret);
    }
    
    
    int main(void)
    {
        // Initialize.
        log_init();
        timer_init();
        uart_init();
        buttons_leds_init();
        db_discovery_init();
        power_management_init();
        ble_stack_init();
        gatt_init();
        nus_c_init();
        scan_init();

  • Well, the range seems to be getting better at least. Are you testing on nRF52840 Development Kits, or custom boards? It might be related to your antenna or matching circuit if this is a custom board.

    Best regards,

    Simon

  • I am using one customized board which is Raytac MDBT50Q-1MV2 module (www.raytac.com/.../ins.php on my board, which is working as the peripheral role. For the central unit, I am using your official development board. 

Related