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

Question about BLE_GAP_TX_POWER_ROLE_CONN

Documentation states “When a connection is created it will inherit the transmit power from the initiator or advertiser leading to the connection.” In my BLE event handler, in the case GAP_BLE_EVT_CONNECTED, I do the following:

uint8_t the_handle = p_ble_evt->evt.gap_evt.conn_handle;

sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, the_handle, 7);

Without having set the tx power in the central's advertising data, will the peripheral know what the power is that it should inherit? Or does the sd_ble_gap_tx_power_set() function also take care of this?

  • "When a connection is created it will inherit the transmit power from the initiator or advertiser leading to the connection"

    This just means that you don't necessarily have to set the TX power for the connection, rather you would just have to set it once, as an advertiser (peripheral) or scanner (Central). Then, the TX Power during connection will be inherited from what you set previously.

    So in a central's main you could:

    static void tx_power_set(void)
    {
        ret_code_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0, TX_POWER_LEVEL);
        APP_ERROR_CHECK(err_code);
    }
    
    
    int main(void)
    {
    
        app_init()
        tx_power_set();
    
        for (;;)
        {
            idle_state_handle();
    
        }
    }

    Notice the role is SCAN, so you scan with that TX Power level, and when you connect, the same power level is inherited, so there is no need to set it for the connection as well.

    In a peripheral's main, you could:

    static void tx_power_set(void)
    {
        ret_code_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL);
        APP_ERROR_CHECK(err_code);
    }
    
    
    int main(void)
    {
    
        app_init()
        tx_power_set();
    
        for (;;)
        {
            idle_state_handle();
    
        }
    }

    The role here is ADV, so the peripheral advertises with this TX Power level, and inherits the same level for the connection.

    The Central doesn't control/set the peripheral's TX Power or vice versa, they are each responsible for setting it themselves.

    Hope this makes sense

  • is correct here. You can also check out this thread, where the TX power settings are discussed in detail as well.

    Best regards,

    Simon

Related