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

DFU bootloader reduce TX Power, but how to get conn_handle?

I would like reduce TX Power in DFU secure bootloader, I would like use sd_ble_gap_tx_power_set function but I faced with the following problem, I don't know how to get conn_handle.
I saw nrf_dfu_ble.c file and saw static variable m_conn_handle but how can I extract it without code modification?


My approach the following:
static void dfu_observer(nrf_dfu_evt_type_t evt_type)
{
    switch (evt_type) {
    case NRF_DFU_EVT_TRANSPORT_ACTIVATED:
        sd_ble_gap_tx_power_set(
            BLE_GAP_TX_POWER_ROLE_CONN,
            0, //WTF? How to get conection handle?
            -16);
        break;
    }
}


Any advice? Any other ways to change TX power?

Thank you!
Parents
  • Hi,

    You can register a new BLE observer as shown below to get access to the connection handle without modifying the BLE transport files.

    #include "ble.h"
    #include "nrf_sdh_ble.h"
    
    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        uint32_t                    err_code;
        uint16_t                    conn_handle;
    
        switch (p_ble_evt->header.evt_id)
        {
           case BLE_GAP_EVT_CONNECTED:
                conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, conn_handle, -16);
                APP_ERROR_CHECK(err_code);
                break;
           default:
              break;
        }
    }
              
    NRF_SDH_BLE_OBSERVER(m_ble_evt_observer, 0, ble_evt_handler, NULL);

    Best regards,

    Vidar

  • Wow! NRF_SDH_BLE_OBSERVER allow register several observers really useful but that not obvious :)
    Thank you Vidar!

Reply Children
No Data
Related