Configuring TX power level on the central device - nrf52840 / VS code / nrf connect / zephyr

Hi, 

I am trying to set the Tx power level on the central device, I have followed the nordic example samples/bluetooth/hci_pwr_ctrl in the Zephyr tree. But it only sets for the peripheral device and it works fine. 

I tried following the same steps to set the central device and I was not able to do so. 

1.Can we set the TX power level on the central device (I am using nrf52840) using zephyr? I am using the Central uart code.

2. What is the TX power level set on the Central device by default?

3. Is there any example codes I can refer to that sets the TX power on the central device?

I am using nRF Connect SDK v2.9.0[nrf]

Software - VS Code

Board - nrf52840-DK

Kindly let me know. 

Thanks, 

Mujeefa

  • Hello Mujeefa,

    1. ''Can we set the TX power level on the central device (I am using nrf52840) using zephyr? I am using the Central uart code.''

    3. ''Is there any example codes I can refer to that sets the TX power on the central device?''

    Yes, you can set it the TX power level on the central device. This can be done by both from configuration and runtime. If you want to change it statically then you need to add

    CONFIG_BT_CTLR_TX_PWR_* (you can change power upto 8 dbM) in thprj.config file (Configuring transmission power).

    For runtime, you can add this 

    CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y (same as hci_pwr_control sample) in config file and after this, in your code, you can use the HCI command to set the TX power (to set the TX power dynamically).
    static void set_tx_power(uint8_t handle_type, uint16_t handle, int8_t tx_pwr_lvl)
    {
    	struct bt_hci_cp_vs_write_tx_power_level *cp;
    	struct bt_hci_rp_vs_write_tx_power_level *rp;
    	struct net_buf *buf, *rsp = NULL;
    	int err;
    
    	buf = bt_hci_cmd_create(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL,
    				sizeof(*cp));
    	if (!buf) {
    		printk("Unable to allocate command buffer\n");
    		return;
    	}
    
    	cp = net_buf_add(buf, sizeof(*cp));
    	cp->handle = sys_cpu_to_le16(handle);
    	cp->handle_type = handle_type;
    	cp->tx_power_level = tx_pwr_lvl;
    
    	err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL,
    				   buf, &rsp);
    	if (err) {
    		printk("Set Tx power err: %d\n", err);
    		return;
    	}
    
    	rp = (void *)rsp->data;
    	printk("Actual Tx Power: %d\n", rp->selected_tx_power);
    
    	net_buf_unref(rsp);
    }
     2. What is the TX power level set on the Central device by default?
    0dbM
  • Hi Kazi, 

    Thank you so much for your reply. Appreciate your help. I will try this out and will keep you posted. Wondering if you could suggest me ways, I could verify that the BLE is running at 8dBM? From the software as well as practically?

    Thanks,

    Mujeefa 

Related