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

control the power in ble_app_blinky_c_pca10056_s140 by changing the code in main.c

I figured that I could put

#define TX_POWER_PHIL  +8    /**  -40,-20,-16,-12,-8,-4,0,+2,+3,+4,+5,+6,+7,+8  phil  **/

and then make two changes to

static void advertising_init(void)
{
    ret_code_t    err_code;
    ble_advdata_t advdata;
    ble_advdata_t srdata;
    int8_t tx_power = TX_POWER_PHIL; //phil

    ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance = true;
    advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;


    memset(&srdata, 0, sizeof(srdata));
    srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    srdata.uuids_complete.p_uuids  = adv_uuids;

    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);

    err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
    APP_ERROR_CHECK(err_code);

    ble_gap_adv_params_t adv_params;

    // Set advertising parameters.
    memset(&adv_params, 0, sizeof(adv_params));

    adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;
    adv_params.duration        = APP_ADV_DURATION;
    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.p_peer_addr     = NULL;
    adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    adv_params.interval        = APP_ADV_INTERVAL;

    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV,m_adv_handle, tx_power); //phil
    APP_ERROR_CHECK(err_code);  //phil
}

and this would change the power level in Blinky.  But in the BLinky client I cannot find advertising_init so I am not sure where to put the power change.

Parents Reply Children
  • You can call this anywhere before start advertisment, scanning or connection.

  • I tried the following code and I get an error

    note: expected 'uint16_t {aka short unsigned int}' but argument is of type 'ble_gap_scan_params_t {aka const struct <anonymous>}'

    so I am still not sure where to place the call to sd_ble_gap_tx_power_set  change the power.

    thanks

    Phil

    /**@brief Function to start scanning.
     */
    static void scan_start(void)
    {
        ret_code_t err_code;
        int8_t tx_power = TX_POWER_PHIL; //phil

        (void) sd_ble_gap_scan_stop();

        err_code = sd_ble_gap_scan_start(&m_scan_params, &m_scan_buffer);
        APP_ERROR_CHECK(err_code);

        bsp_board_led_off(CENTRAL_CONNECTED_LED);
        bsp_board_led_on(CENTRAL_SCANNING_LED);

        err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT,m_scan_params, tx_power); //phil
        APP_ERROR_CHECK(err_code);  //phil
    }

  • I read where if the ROLE is SCAN_INIT then the handle is ignored.  So I changed the code to

    supply a dummy handle.  This compiles correctly.  Now I am going to test the unit.

    I also put the call to change the power in front of the call to start the scan.

    thanks

    Phil

    static void scan_start(void)
    {
        ret_code_t err_code;
        int8_t tx_power = TX_POWER_PHIL; //phil
        uint16_t dummy_handle=0; //phil handle is ignored on role SCAN_INIT

        err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT,dummy_handle, tx_power); //phil
        APP_ERROR_CHECK(err_code);  //phil

        (void) sd_ble_gap_scan_stop();

        err_code = sd_ble_gap_scan_start(&m_scan_params, &m_scan_buffer);
        APP_ERROR_CHECK(err_code);

        bsp_board_led_off(CENTRAL_CONNECTED_LED);
        bsp_board_led_on(CENTRAL_SCANNING_LED);

      
    }

Related