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

How to set the transmit power when using nRF52833 for broadcasting on nRF Connect SDK ?

I am using nRF52833 on ncs to turn on the extended broadcast. After referring to the corresponding settings, I found that the transmit power setting does not take effect. Is the setting wrong? Or need other methods to set the transmit power?

The version I use is ncs v1.6.0

Below is part of my code:

in main.c:

#include <zephyr.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <sys/util.h>

#include <bluetooth/hci.h>
#include <bluetooth/hci_vs.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/controller.h>

#include <sys/byteorder.h>
#include <bluetooth/hci_vs.h>

#include <logging/log.h>
LOG_MODULE_REGISTER(mt_adv, 3);

static struct bt_le_ext_adv *adv_set;

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, BT_DATA_UUID128_SOME),
	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
		      	0x4C, 0x00, 			/* Apple. */
		      	0x02, 0x15, 			/* iBeacon. */
		      	0x01, 0x12, 0x23, 0x34,	/* UUID-1. */
				0x45, 0x56, 0x67, 0x78,	/* UUID-2. */
				0x89, 0x9A, 0xAB, 0xBC,	/* UUID-3. */
				0xCD, 0xDE, 0xEF, 0xF0,	/* UUID-4. */
		      	0x66,0x66, 				/* Major. */
		      	0x66,0x66, 				/* Minor. */
		      	0xC5),					/* Calibrated RSSI @ 1m. */
    BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, (sizeof(CONFIG_BT_DEVICE_NAME) - 1))
};

const static struct bt_le_adv_param param =
		BT_LE_ADV_PARAM_INIT(
                     BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | BT_LE_ADV_OPT_CONNECTABLE,
				     BT_GAP_ADV_FAST_INT_MIN_2,
				     BT_GAP_ADV_FAST_INT_MIN_2,
				     NULL);

void get_tx_power(uint8_t handle_type, uint16_t handle, int8_t *tx_pwr_lvl)
{
	struct bt_hci_cp_vs_read_tx_power_level *cp;
	struct bt_hci_rp_vs_read_tx_power_level *rp;
	struct net_buf *buf, *rsp = NULL;
	int err;

	*tx_pwr_lvl = 0xFF;
	buf = bt_hci_cmd_create(BT_HCI_OP_VS_READ_TX_POWER_LEVEL,
				sizeof(*cp));
	if (!buf) {
		LOG_ERR("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;

	err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_TX_POWER_LEVEL,
				   buf, &rsp);
	if (err) {
		uint8_t reason = rsp ?
			((struct bt_hci_rp_vs_read_tx_power_level *)
			  rsp->data)->status : 0;
		LOG_ERR("Read Tx power err: %d reason 0x%02x\n", err, reason);
		return;
	}

	rp = (void *)rsp->data;
	*tx_pwr_lvl = rp->tx_power_level;

	net_buf_unref(rsp);
}

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) {
        LOG_INF("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) {
        uint8_t reason = rsp ? ((struct bt_hci_rp_vs_write_tx_power_level *)rsp->data)->status : 0;
        LOG_INF("Set Tx power err: %d reason 0x%02x\n", err, reason);
        return;
    }

    rp = (void *)rsp->data;
    LOG_INF("Actual Tx Power: %d\n", rp->selected_tx_power);

    net_buf_unref(rsp);
}

void main(void)
{
    int err = bt_enable(NULL);
    if (err) {
        LOG_ERR("[%04d] Bluetooth init failed (err %d).\n", __LINE__, err);
        return;
    }
    LOG_INF("[%04d] Bluetooth initialized.", __LINE__);

    int tx_power = 0;
    set_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0, tx_power);

    err = bt_le_ext_adv_create(&param, NULL, &adv_set);
    if (err) {
        LOG_ERR("[%04d] Create extended advertising set_id failed (err %d).\n", __LINE__, err);
        return;
    }

    err = bt_le_ext_adv_set_data(adv_set, ad, ARRAY_SIZE(ad), NULL, 0);
    if (err) {
        LOG_ERR("[%04d] Failed to set advertising data (%d).\n", __LINE__, err);
        return;
    }

    err = bt_le_ext_adv_start(adv_set, NULL);
    if (err) {
        LOG_ERR("[%04d] Extended advertising failed to start (err %d).\n", __LINE__, err);
        return;
    }
    LOG_INF("[%04d] Extended advertising enable...", __LINE__);
}

in prj.conf:
# Bluetooth.
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=n
CONFIG_BT_BROADCASTER=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="NCS-adv"

CONFIG_BT_LL_SW_SPLIT=y
CONFIG_BT_LL_SOFTDEVICE=n
CONFIG_BT_CTLR=y
CONFIG_BT_CTLR_CONN_RSSI=y
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y

CONFIG_BT_EXT_ADV=y
CONFIG_BT_PER_ADV=y
CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_CTLR_PHY_CODED=y

Parents
  • Hi Kenny, 


    I haven't tried to test on my own but as far as I know for extended advertising you set the tx_power in the ad set. Have a look here.

  • Hi,Hung Build,

    I tried it, but it still didn't work...

    Can you give an example? And related macros.

  • Hi Kenny,

    The following code worked for me (based on your mt_advertising) 

    /* Copyright (C) Shenzhen Minew Technologies Co., Ltd 
       All rights reserved. */
    
    #include <zephyr.h>
    #include <zephyr/types.h>
    #include <stddef.h>
    #include <sys/util.h>
    
    #include <bluetooth/hci.h>
    #include <bluetooth/hci_vs.h>
    #include <bluetooth/conn.h>
    #include <bluetooth/uuid.h>
    #include <bluetooth/gatt.h>
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/controller.h>
    #include <bluetooth/hci_vs.h>
    #include <logging/log.h>
    #include <sys/byteorder.h>
    LOG_MODULE_REGISTER(mt_advertising, 3);
    
    static struct bt_le_ext_adv *adv_set;
    static struct bt_le_ext_adv *adv_set_1;
    
    /**
     * @brief 广播数据.
     */
    static const struct bt_data ad[] = {
    	BT_DATA_BYTES(BT_DATA_FLAGS, BT_DATA_UUID128_SOME),
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    		      	0x4C, 0x00, 			/* Apple. */
    		      	0x02, 0x15, 			/* iBeacon. */
    		      	0x01, 0x12, 0x23, 0x34,	/* UUID-1. */
    				0x45, 0x56, 0x67, 0x78,	/* UUID-2. */
    				0x89, 0x9A, 0xAB, 0xBC,	/* UUID-3. */
    				0xCD, 0xDE, 0xEF, 0xF0,	/* UUID-4. */
    		      	0x66,0x66, 				/* Major. */
    		      	0x66,0x66, 				/* Minor. */
    		      	0xC5),					/* Calibrated RSSI @ 1m. */
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    				0x39, 0x06,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0xFF),
        BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, (sizeof(CONFIG_BT_DEVICE_NAME) - 1))
    };
    static const struct bt_data ad2[] = {
    	BT_DATA_BYTES(BT_DATA_FLAGS, BT_DATA_UUID128_SOME),
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    		      	0x4C, 0x00, 			/* Apple. */
    		      	0x02, 0x15, 			/* iBeacon. */
    		      	0x01, 0x12, 0x23, 0x34,	/* UUID-1. */
    				0x45, 0x56, 0x67, 0x78,	/* UUID-2. */
    				0x89, 0x9A, 0xAB, 0xBC,	/* UUID-3. */
    				0xCD, 0xDE, 0xEF, 0xF0,	/* UUID-4. */
    		      	0x66,0x66, 				/* Major. */
    		      	0x66,0x66, 				/* Minor. */
    		      	0xC5),					/* Calibrated RSSI @ 1m. */
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    				0x39, 0x06,
    				
    				0xFF),
        BT_DATA(BT_DATA_NAME_COMPLETE, "NCS-123", (sizeof(CONFIG_BT_DEVICE_NAME) - 1))
    };
    
    /**
     * @brief 广播类型等参数.
     */
    const static struct bt_le_adv_param param =
    		BT_LE_ADV_PARAM_INIT(
                         BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | 
                           BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_TX_POWER,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     NULL);
    
    /**
     * @brief 主函数入口.
     */
    
     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) {
            LOG_INF("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) {
            uint8_t reason = rsp ? ((struct bt_hci_rp_vs_write_tx_power_level *)rsp->data)->status : 0;
            LOG_INF("Set Tx power err: %d reason 0x%02x\n", err, reason);
            return;
        }
    
        rp = (void *)rsp->data;
        LOG_INF("Actual Tx Power: %d\n", rp->selected_tx_power);
    
        net_buf_unref(rsp);
    }
    
    void main(void)
    {
        int err = bt_enable(NULL);
        if (err) {
            LOG_ERR("[%04d] Bluetooth init failed (err %d).\n", __LINE__, err);
            return;
        }
        LOG_INF("[%04d] Bluetooth initialized.", __LINE__);
        
        err = bt_le_ext_adv_create(&param, NULL, &adv_set);
        
        if (err) {
            LOG_ERR("[%04d] Create extended advertising set_id failed (err %d).\n", __LINE__, err);
            return;
        }
        LOG_INF("[%04d] first set.", __LINE__);
      
        err = bt_le_ext_adv_create(&param, NULL, &adv_set_1);
        if (err) {
            LOG_ERR("[%04d] Create extended advertising set_id_1 failed (err %d).\n", __LINE__, err);
            return;
        }
        LOG_INF("[%04d] second set.", __LINE__);
        
        err = bt_le_ext_adv_set_data(adv_set, ad, ARRAY_SIZE(ad), NULL, 0);
        if (err) {
            LOG_ERR("[%04d] Failed to set advertising data (%d).\n", __LINE__, err);
            return;
        }
    
        err = bt_le_ext_adv_set_data(adv_set_1, ad2, ARRAY_SIZE(ad2), NULL, 0);
        if (err) {
            LOG_ERR("[%04d] Failed to set advertising data (%d).\n", __LINE__, err);
            return;
        }
    
        err = bt_le_ext_adv_start(adv_set, NULL);
        if (err) {
            LOG_ERR("[%04d] Extended advertising failed to start (err %d).\n", __LINE__, err);
            return;
        }
        
        /*err = bt_le_ext_adv_start(adv_set_1, NULL);
        if (err) {
            LOG_ERR("[%04d] Extended advertising failed to start (err %d).\n", __LINE__, err);
            return;
        }*/
        int tx_power = 4;
        set_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0, tx_power);
        LOG_INF("[%04d] Extended advertising enable...", __LINE__);
    }

    The difference is more clear if you try +4 and -18 for example. 
    I tested using Softdevice controller. 

Reply
  • Hi Kenny,

    The following code worked for me (based on your mt_advertising) 

    /* Copyright (C) Shenzhen Minew Technologies Co., Ltd 
       All rights reserved. */
    
    #include <zephyr.h>
    #include <zephyr/types.h>
    #include <stddef.h>
    #include <sys/util.h>
    
    #include <bluetooth/hci.h>
    #include <bluetooth/hci_vs.h>
    #include <bluetooth/conn.h>
    #include <bluetooth/uuid.h>
    #include <bluetooth/gatt.h>
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/controller.h>
    #include <bluetooth/hci_vs.h>
    #include <logging/log.h>
    #include <sys/byteorder.h>
    LOG_MODULE_REGISTER(mt_advertising, 3);
    
    static struct bt_le_ext_adv *adv_set;
    static struct bt_le_ext_adv *adv_set_1;
    
    /**
     * @brief 广播数据.
     */
    static const struct bt_data ad[] = {
    	BT_DATA_BYTES(BT_DATA_FLAGS, BT_DATA_UUID128_SOME),
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    		      	0x4C, 0x00, 			/* Apple. */
    		      	0x02, 0x15, 			/* iBeacon. */
    		      	0x01, 0x12, 0x23, 0x34,	/* UUID-1. */
    				0x45, 0x56, 0x67, 0x78,	/* UUID-2. */
    				0x89, 0x9A, 0xAB, 0xBC,	/* UUID-3. */
    				0xCD, 0xDE, 0xEF, 0xF0,	/* UUID-4. */
    		      	0x66,0x66, 				/* Major. */
    		      	0x66,0x66, 				/* Minor. */
    		      	0xC5),					/* Calibrated RSSI @ 1m. */
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    				0x39, 0x06,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
    				0xFF),
        BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, (sizeof(CONFIG_BT_DEVICE_NAME) - 1))
    };
    static const struct bt_data ad2[] = {
    	BT_DATA_BYTES(BT_DATA_FLAGS, BT_DATA_UUID128_SOME),
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    		      	0x4C, 0x00, 			/* Apple. */
    		      	0x02, 0x15, 			/* iBeacon. */
    		      	0x01, 0x12, 0x23, 0x34,	/* UUID-1. */
    				0x45, 0x56, 0x67, 0x78,	/* UUID-2. */
    				0x89, 0x9A, 0xAB, 0xBC,	/* UUID-3. */
    				0xCD, 0xDE, 0xEF, 0xF0,	/* UUID-4. */
    		      	0x66,0x66, 				/* Major. */
    		      	0x66,0x66, 				/* Minor. */
    		      	0xC5),					/* Calibrated RSSI @ 1m. */
    	BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA,
    				0x39, 0x06,
    				
    				0xFF),
        BT_DATA(BT_DATA_NAME_COMPLETE, "NCS-123", (sizeof(CONFIG_BT_DEVICE_NAME) - 1))
    };
    
    /**
     * @brief 广播类型等参数.
     */
    const static struct bt_le_adv_param param =
    		BT_LE_ADV_PARAM_INIT(
                         BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | 
                           BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_TX_POWER,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     NULL);
    
    /**
     * @brief 主函数入口.
     */
    
     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) {
            LOG_INF("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) {
            uint8_t reason = rsp ? ((struct bt_hci_rp_vs_write_tx_power_level *)rsp->data)->status : 0;
            LOG_INF("Set Tx power err: %d reason 0x%02x\n", err, reason);
            return;
        }
    
        rp = (void *)rsp->data;
        LOG_INF("Actual Tx Power: %d\n", rp->selected_tx_power);
    
        net_buf_unref(rsp);
    }
    
    void main(void)
    {
        int err = bt_enable(NULL);
        if (err) {
            LOG_ERR("[%04d] Bluetooth init failed (err %d).\n", __LINE__, err);
            return;
        }
        LOG_INF("[%04d] Bluetooth initialized.", __LINE__);
        
        err = bt_le_ext_adv_create(&param, NULL, &adv_set);
        
        if (err) {
            LOG_ERR("[%04d] Create extended advertising set_id failed (err %d).\n", __LINE__, err);
            return;
        }
        LOG_INF("[%04d] first set.", __LINE__);
      
        err = bt_le_ext_adv_create(&param, NULL, &adv_set_1);
        if (err) {
            LOG_ERR("[%04d] Create extended advertising set_id_1 failed (err %d).\n", __LINE__, err);
            return;
        }
        LOG_INF("[%04d] second set.", __LINE__);
        
        err = bt_le_ext_adv_set_data(adv_set, ad, ARRAY_SIZE(ad), NULL, 0);
        if (err) {
            LOG_ERR("[%04d] Failed to set advertising data (%d).\n", __LINE__, err);
            return;
        }
    
        err = bt_le_ext_adv_set_data(adv_set_1, ad2, ARRAY_SIZE(ad2), NULL, 0);
        if (err) {
            LOG_ERR("[%04d] Failed to set advertising data (%d).\n", __LINE__, err);
            return;
        }
    
        err = bt_le_ext_adv_start(adv_set, NULL);
        if (err) {
            LOG_ERR("[%04d] Extended advertising failed to start (err %d).\n", __LINE__, err);
            return;
        }
        
        /*err = bt_le_ext_adv_start(adv_set_1, NULL);
        if (err) {
            LOG_ERR("[%04d] Extended advertising failed to start (err %d).\n", __LINE__, err);
            return;
        }*/
        int tx_power = 4;
        set_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0, tx_power);
        LOG_INF("[%04d] Extended advertising enable...", __LINE__);
    }

    The difference is more clear if you try +4 and -18 for example. 
    I tested using Softdevice controller. 

Children
Related