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

[nRF52840 SDK 16.0.0] ble beacon example change TX power level

Hi all,

I'm using the "ble_beacon_app" example from the SDK 16.0.0 with the nRF52840 DK. I would like to change the TX power level.

In main.c function, I tried to change the advertising_init() by adding the following code:

    int8_t tx_power_level = 8;
    advdata.p_tx_power_level = &tx_power_level;

I get no error by compiling the project, but the application doesn't work and I cannot see any device from the nRF connect App scanner.

Could you please help me where is the problem? Thank you in advance

  • Hi,

    The code you have added is for including the TX power level that the beacon uses in the advertising packet. It does not change the actual TX power. The reason that the application does not work with these additions is most likely that the advertising packet was already full before you added this additional data field, generating an error when you run the application.

    To change the actual TX power level for the advertising, you should call sd_ble_gap_tx_power_set(). You can add this to the end of advertising_init() function to set +8 dBm output power:

    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_adv_handle, 8);
    APP_ERROR_CHECK(err_code);

    Best regards,
    Jørgen

  • Ok thank you so much!

    So, do I need only to add your code in the init function, or should I also change the advdata.p_tx_power_level in a different way? I do not full understand the functionality of this latter parameter.

    I noticed that in this example project, the function  sd_ble_gap_tx_power_set() is not used at all. does it means that the device will keep the default settings of 0 dBm?

    Thank you again!

  • alfiero said:
    So, do I need only to add your code in the init function, or should I also change the advdata.p_tx_power_level in a different way? I do not full understand the functionality of this latter parameter.

    No, you do not need to add this. As I said, there is most likely not enough space in the advertising packet to include this anyway. The iBeacon format (which ble_app_beacon closely implements) does not include the parameter.

    alfiero said:
    I noticed that in this example project, the function  sd_ble_gap_tx_power_set() is not used at all. does it means that the device will keep the default settings of 0 dBm?

    Yes, the default of 0 dBm will be used when the tx_power is not explicitly set.

  • Ok, thank you so much, Jørgen!

    Another question (sorry to bother you): I saw that for 'long-range' mode, the data rate should be 125 kbps, so as to reduce receiving errors I guess. What is the default bitrate in this example? 1Mbps? How can I change it to 125 kbps to combine it with the +8 dBm output power, in order to achieve a very long-range transmission? Thank you in advance!!

  • I tried to put this code at the end of the advertising_init function, to get the lowest throughput for advertising, which should be 125 kbps (I saw it is supported for advertising non-connectable mode in the latest version of s140):

    //set PHY mode: 
        ble_gap_phys_t const myPhys =
                {
                    .rx_phys = BLE_GAP_PHY_CODED, //lowest datarate
                    .tx_phys = BLE_GAP_PHY_CODED,
                };
    
        err_code = sd_ble_gap_phy_update(m_adv_handle, &myPhys);
        APP_ERROR_CHECK(err_code);

    I get no errors from the compiler, but the application doesn't work.

    I would like to set the 125 kbps data rate to achieve the long-range mode for advertising.

    Any suggestions? Thank you in advance!!

Related