coded_phy and 1Mbit/s

I'm thinking to have  a cental_and peripheral at the same time.

Using the the standard  ble I have to setup the configuration.(Who is the Central_uart  and the Periheral ( the central unit can be connected up to 4 peripheral ))

At the same time the device have to  be MemFault  client (Mds client)  and other type of clients. 

The central_uart is  connected with the  peripheral_uart  (1,2,3,4) using a coded_phy (125Kb/s). I see that there is an examples that use coded_phy  (central_hr_coded and periphera_hr_coded) The problem is that for me is not clear how to make a central_peripheral_coded_phy uart I have the error:Faild to create advertizer (-11) 

Where I can find documentation on How to use extended advetize?

Best Regards

Novello G. 

  • Hi,

    The peripheral_hr_coded sample that you have found does demonstrate extended advertising (that is needed to advertise on coded PHY). So these two samples in sum should demonstrate what you are after (essentially by combining them).

    What exactly is the problem? Where is the error printed and where to the error value come from? Assuming -11 is an error code it would be -EAGAIN, which could be returned by bt_le_ext_adv_create(). Is that the case here? If so, perhaps this thread is relevant, though there could also be other causes for this.

  • This is My code .

    #include <zephyr/bluetooth/bluetooth.h>
    #include <zephyr/bluetooth/conn.h>
    #include <zephyr/bluetooth/uuid.h>
    #include <zephyr/bluetooth/gatt.h>
    #include <bluetooth/gatt_dm.h>
    #include <bluetooth/scan.h>
    #include <bluetooth/conn.h>
    #include <zephyr/bluetooth/services/bas.h>
    #include <zephyr/bluetooth/services/hrs.h>
    #include <bluetooth/services/hrs_client.h>
    
    #include <dk_buttons_and_leds.h>
    
    #include <zephyr/settings/settings.h>
    
    #include <zephyr/kernel.h>
    static void start_advertising_coded(struct k_work *work);
    //static void notify_work_handler(struct k_work *work);
    
    static K_WORK_DEFINE(start_advertising_worker, start_advertising_coded);
    //static K_WORK_DELAYABLE_DEFINE(notify_work, notify_work_handler);
    
    static struct bt_le_ext_adv *adv;
    
    #define STACKSIZE 1024
    #define PRIORITY 7
    
    #define RUN_STATUS_LED             DK_LED1
    #define CENTRAL_CON_STATUS_LED	   DK_LED2
    #define PERIPHERAL_CONN_STATUS_LED DK_LED3
    //static struct bt_conn *default_conn;
    #define RUN_LED_BLINK_INTERVAL 1000
    
    #define HRS_QUEUE_SIZE 16
    
    static const struct bt_data ad[] = {
    	BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE,
    		(CONFIG_BT_DEVICE_APPEARANCE >> 0) & 0xff,
    		(CONFIG_BT_DEVICE_APPEARANCE >> 8) & 0xff),
    	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
    	BT_DATA_BYTES(BT_DATA_UUID16_ALL,
    		      BT_UUID_16_ENCODE(BT_UUID_HRS_VAL)), /* Heart Rate Service */
    };
    
    static const struct bt_data sd[] = {
    	BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME)
    };
    
    K_MSGQ_DEFINE(hrs_queue, sizeof(struct bt_hrs_client_measurement), HRS_QUEUE_SIZE, 4);
    
    static struct bt_hrs_client hrs_c;
    static struct bt_conn *central_conn;
    
    static const char * const sensor_location_str[] = {
    	"Other",
    	"Chest",
    	"Wrist",
    	"Finger",
    	"Hand",
    	"Ear lobe",
    	"Foot"
    };
    
    static int create_advertising_coded(void)
    {
    	int err;
    	struct bt_le_adv_param param =
    		BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
    				     BT_LE_ADV_OPT_EXT_ADV |
    				     BT_LE_ADV_OPT_CODED,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     BT_GAP_ADV_FAST_INT_MAX_2,
    				     NULL);
    
    	err=bt_le_ext_adv_stop(&adv);
    	
    	err = bt_le_ext_adv_create(&param, NULL, &adv);
    	if (err) {
    		printk("!!!!!!!!!!!!!!Failed to create advertiser set (err %d)\n", err);
    		return err;
    	}
    
    	printk("Created adv: %p\n", adv);
    
    	err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
    	if (err) {
    		printk("Failed to set advertising data (err %d)\n", err);
    		return err;
    	}
    
    	return 0;
    }
    
    static void start_advertising_coded(struct k_work *work)
    {
    	int err;
    
    	err = bt_le_ext_adv_start(adv, NULL);
    	if (err) {
    		printk("Failed to start advertising set (err %d)\n", err);
    		return;
    	}
    
    	printk("Advertiser %p set started\n", adv);
    }
    
    static void hrs_sensor_location_read_cb(struct bt_hrs_client *hrs_c,
    					enum bt_hrs_client_sensor_location location,
    					int err)
    {
    	if (err) {
    		printk("HRS Sensor Body Location read error (err %d)\n", err);
    		return;
    	}
    
    	printk("Heart Rate Sensor body location: %s\n", sensor_location_str[location]);
    }
    
    static void hrs_measurement_notify_cb(struct bt_hrs_client *hrs_c,const struct bt_hrs_client_measurement *meas,int err)
    {
    	if (err) {
    		printk("Error during receiving Heart Rate Measurement notification, err: %d\n",
    			err);
    		return;
    	}
    
    	printk("Heart Rate Measurement notification received:\n\n");
    	printk("\tHeart Rate Measurement Value Format: %s\n",
    		meas->flags.value_format ? "16 - bit" : "8 - bit");
    	printk("\tSensor Contact detected: %d\n", meas->flags.sensor_contact_detected);
    	printk("\tSensor Contact supported: %d\n", meas->flags.sensor_contact_supported);
    	printk("\tEnergy Expended present: %d\n", meas->flags.energy_expended_present);
    	printk("\tRR-Intervals present: %d\n", meas->flags.rr_intervals_present);
    
    	printk("\n\tHeart Rate Measurement Value: %d bpm\n", meas->hr_value);
    
    	if (meas->flags.energy_expended_present) {
    		printk("\n\tEnergy Expended: %d J\n", meas->energy_expended);
    	}
    
    	if (meas->flags.rr_intervals_present) {
    		printk("\t RR-intervals: ");
    		for (size_t i = 0; i < meas->rr_intervals_count; i++) {
    			printk("%d ", meas->rr_intervals[i]);
    		}
    	}
    
    	printk("\n");
    
    	err = k_msgq_put(&hrs_queue, meas, K_NO_WAIT);
    	if (err) {
    		printk("Notification queue is full. Discarting HRS notification (err %d)\n", err);
    	}
    }
    
    static void discovery_completed_cb(struct bt_gatt_dm *dm,
    				   void *context)
    {
    	int err;
    
    	printk("The discovery procedure succeeded\n");
    
    	bt_gatt_dm_data_print(dm);
    
    	err = bt_hrs_client_handles_assign(dm, &hrs_c);
    	if (err) {
    		printk("Could not init HRS client object (err %d)\n", err);
    		return;
    	}
    
    	err = bt_hrs_client_sensor_location_read(&hrs_c, hrs_sensor_location_read_cb);
    	if (err) {
    		printk("Could not read Heart Rate Sensor location (err %d)\n", err);
    	}
    
    	err = bt_hrs_client_measurement_subscribe(&hrs_c, hrs_measurement_notify_cb);
    	if (err) {
    		printk("Could not subscribe to Heart Rate Measurement characteristic (err %d)\n",
    		       err);
    	}
    
    	err = bt_gatt_dm_data_release(dm);
    	if (err) {
    		printk("Could not release the discovery data (err %d)\n", err);
    	}
    }
    
    static void discovery_not_found_cb(struct bt_conn *conn,
    				   void *context)
    {
    	printk("Heart Rate Service could not be found during the discovery\n");
    }
    
    static void discovery_error_found_cb(struct bt_conn *conn,
    				     int err, void *context)
    {
    	printk("The discovery procedure failed with %d\n", err);
    }
    
    static const struct bt_gatt_dm_cb discovery_cb = {
    	.completed = discovery_completed_cb,
    	.service_not_found = discovery_not_found_cb,
    	.error_found = discovery_error_found_cb
    };
    
    static void gatt_discover(struct bt_conn *conn)
    {
    	int err;
    
    	err = bt_gatt_dm_start(conn, BT_UUID_HRS, &discovery_cb, NULL);
    	if (err) {
    		printk("Could not start the discovery procedure, error "
    			   "code: %d\n", err);
    	}
    }
    
    static void auth_cancel(struct bt_conn *conn)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	printk("Pairing cancelled: %s\n", addr);
    }
    
    static void pairing_complete(struct bt_conn *conn, bool bonded)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	printk("Pairing completed: %s, bonded: %d\n", addr, bonded);
    }
    
    static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	printk("Pairing failed conn: %s, reason %d\n", addr, reason);
    }
    
    static const struct bt_conn_auth_cb auth_callbacks = {
    	.cancel = auth_cancel
    };
    
    static struct bt_conn_auth_info_cb conn_auth_info_callbacks = {
    	.pairing_complete = pairing_complete,
    	.pairing_failed = pairing_failed
    };
    
    static int scan_start(void)
    {
    	int err = bt_scan_start(BT_SCAN_TYPE_SCAN_PASSIVE);
    
    	if (err) {
    		printk("Scanning failed to start (err %d)\n", err);
    	}
    
    	return err;
    }
    
    static void connected(struct bt_conn *conn, uint8_t conn_err)
    {
    	int err;
    	struct bt_conn_info info;
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (conn_err) {
    		printk("Failed to connect to %s (%u)\n", addr, conn_err);
    
    		if (conn == central_conn) {
    			bt_conn_unref(central_conn);
    			central_conn = NULL;
    
    			scan_start();
    		}
    
    		return;
    	}
    
    	printk("Connected: %s\n", addr);
    
    	bt_conn_get_info(conn, &info);
    	const struct bt_conn_le_phy_info *phy_info;
    	phy_info = info.le.phy;
    
    	printk("Connected: %s, tx_phy %u, rx_phy %u\n",addr, phy_info->tx_phy, phy_info->rx_phy);
    
    	if (info.role == BT_CONN_ROLE_CENTRAL) {
    		dk_set_led_on(CENTRAL_CON_STATUS_LED);
    
    		err = bt_conn_set_security(conn, BT_SECURITY_L2);
    		if (err) {
    			printk("Failed to set security (err %d)\n", err);
    
    			gatt_discover(conn);
    		}
    	} else {
    		dk_set_led_on(PERIPHERAL_CONN_STATUS_LED);
    	}
    }
    
    static void disconnected(struct bt_conn *conn, uint8_t reason)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	printk("Disconnected: %s (reason %u)\n", addr, reason);
    
    	if (conn == central_conn) {
    		dk_set_led_off(CENTRAL_CON_STATUS_LED);
    
    		bt_conn_unref(central_conn);
    		central_conn = NULL;
    
    		scan_start();
    	} else {
    		dk_set_led_off(PERIPHERAL_CONN_STATUS_LED);
    	}
    }
    
    static void security_changed(struct bt_conn *conn, bt_security_t level,
    			     enum bt_security_err err)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (!err) {
    		printk("Security changed: %s level %u\n", addr, level);
    	} else {
    		printk("Security failed: %s level %u err %d\n", addr, level,
    			err);
    	}
    
    	if (conn == central_conn) {
    		gatt_discover(conn);
    	}
    }
    
    BT_CONN_CB_DEFINE(conn_callbacks) = {
    	.connected = connected,
    	.disconnected = disconnected,
    	.security_changed = security_changed
    };
    #ifdef ORI
    static void scan_filter_match(struct bt_scan_device_info *device_info,
    			      struct bt_scan_filter_match *filter_match,
    			      bool connectable)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
    
    	printk("Filters matched. Address: %s connectable: %d\n",
    		   addr, connectable);
    }
    #else
    
    static void scan_filter_match(struct bt_scan_device_info *device_info,struct bt_scan_filter_match *filter_match,bool connectable)
    {
    	int err;
    	char addr[BT_ADDR_LE_STR_LEN];
    	struct bt_conn_le_create_param *conn_params;
    
    	bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
    
    	printk("Filters matched. Address: %s connectable: %s\n",
    		addr, connectable ? "yes" : "no");
    
    	err = bt_scan_stop();
    	if (err) {
    		printk("Stop LE scan failed (err %d)\n", err);
    	}
    
    	conn_params = BT_CONN_LE_CREATE_PARAM(
    			BT_CONN_LE_OPT_CODED | BT_CONN_LE_OPT_NO_1M/*|BT_LE_ADV_OPT_CONNECTABLE |BT_LE_ADV_OPT_EXT_ADV |BT_LE_ADV_OPT_CODED*/,
    			BT_GAP_SCAN_FAST_INTERVAL,
    			BT_GAP_SCAN_FAST_INTERVAL);
    
    	err = bt_conn_le_create(device_info->recv_info->addr, conn_params,
    				BT_LE_CONN_PARAM_DEFAULT,
    				&central_conn);//default_conn);
    	if (err) {
    		printk("Create conn failed (err %d)\n", err);
    
    		err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
    		if (err) {
    			printk("Scanning failed to start (err %d)\n", err);
    			return;
    		}
    	}
    
    	printk("Connection pending\n");
    }
    #endif
    
    static void scan_connecting_error(struct bt_scan_device_info *device_info)
    {
    	printk("Connecting failed\n");
    }
    
    static void scan_connecting(struct bt_scan_device_info *device_info,
    			    struct bt_conn *conn)
    {
    	central_conn = bt_conn_ref(conn);
    }
    
    BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL,
    		scan_connecting_error, scan_connecting);
    
    // funzione modificata per aggiungere coded phy
    
    static void scan_init(void)
    {
    	int err;
    	
    	struct bt_le_scan_param scan_param=
    	{
    		.type=BT_LE_SCAN_TYPE_ACTIVE,
    		.interval=BT_GAP_SCAN_FAST_INTERVAL,
    		.window=BT_GAP_SCAN_FAST_WINDOW,
    		.options=BT_LE_SCAN_OPT_CODED | BT_CONN_LE_OPT_NO_1M /*|BT_LE_ADV_OPT_CONNECTABLE |BT_LE_ADV_OPT_EXT_ADV |BT_LE_ADV_OPT_CODED*/
    	};
    
    	struct bt_scan_init_param param = {
    		.scan_param = &scan_param,//NULL,
    		.conn_param = NULL,//BT_LE_CONN_PARAM_DEFAULT,
    		.connect_if_match = 0
    	};
    
    	bt_scan_init(&param);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_HRS);
    	if (err) {
    		printk("Scanning filters cannot be set (err %d)\n", err);
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
    	if (err) {
    		printk("Filters cannot be turned on (err %d)\n", err);
    	}
    }
    
    static void hrs_notify_thread(void)
    {
    	struct bt_hrs_client_measurement meas;
    	uint16_t heart_rate;
    
    	while (1) {
    		k_msgq_get(&hrs_queue, &meas, K_FOREVER);
    
    		if (meas.flags.value_format) {
    			heart_rate = (uint8_t)(meas.hr_value >> 0x08);
    		} else {
    			heart_rate = meas.hr_value;
    		}
    
    		bt_hrs_notify(heart_rate);
    	}
    }
    
    /*
    static int create_advertising_coded(void)
    {
    	int err;
    	struct bt_le_adv_param param =
    		BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_CONNECTABLE |
    				     BT_LE_ADV_OPT_EXT_ADV |
    				     BT_LE_ADV_OPT_CODED,
    				     BT_GAP_ADV_FAST_INT_MIN_2,
    				     BT_GAP_ADV_FAST_INT_MAX_2,
    				     NULL);
    
    	err = bt_le_ext_adv_create(&param, NULL, &adv);
    	if (err) {
    		printk("Failed to create advertiser set (err %d)\n", err);
    		return err;
    	}
    
    	printk("Created adv: %p\n", adv);
    
    	err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
    	if (err) {
    		printk("Failed to set advertising data (err %d)\n", err);
    		return err;
    	}
    
    	return 0;
    }
    
    static void start_advertising_coded(struct k_work *work)
    {
    	int err;
    
    	err = bt_le_ext_adv_start(adv, NULL);
    	if (err) {
    		printk("Failed to start advertising set (err %d)\n", err);
    		return;
    	}
    
    	printk("Advertiser %p set started\n", adv);
    }
    */
    
    void main(void)
    {
    	int err;
    	int blink_status = 0;
    
    	printk("Starting Bluetooth Central and Peripheral Heart Rate relay example\n");
    
    	err = dk_leds_init();
    	if (err) {
    		printk("LEDs init failed (err %d)\n", err);
    		return;
    	}
    
    	err = bt_conn_auth_cb_register(&auth_callbacks);
    	if (err) {
    		printk("Failed to register authorization callbacks.\n");
    		return;
    	}
    
    	err = bt_conn_auth_info_cb_register(&conn_auth_info_callbacks);
    	if (err) {
    		printk("Failed to register authorization info callbacks.\n");
    		return;
    	}
    
    	err = bt_enable(NULL);
    	if (err) {
    		return;
    	}
    	
    
    	if (IS_ENABLED(CONFIG_SETTINGS)) {
    		settings_load();
    	}
    
    	err = bt_hrs_client_init(&hrs_c);
    	if (err) {
    		printk("Heart Rate Service client failed to init (err %d)\n", err);
    		return;
    	}
    
    	scan_init();
    
    	err = scan_start();
    	if (err) {
    		return;
    	}
    	
    
    	
    	printk("Bluetooth initialized\n");
    
    	err = create_advertising_coded();
    	if (err) {
    		printk("Advertising failed to create (err %d)\n", err);
    		return;
    	}
    
    	k_work_submit(&start_advertising_worker);
    	printk("Scanning started\n");
    
    	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
    			      sd, ARRAY_SIZE(sd));
    	if (err) {
    		printk("Advertising failed to start (err %d)\n", err);
    		return;
    	}
    
    	printk("Advertising started\n");
    
    	for (;;) {
    		dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
    		k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
    	}
    }
    
    K_THREAD_DEFINE(hrs_notify_thread_id, STACKSIZE, hrs_notify_thread,
    		NULL, NULL, NULL, PRIORITY, 0, 0);
    
    
    
    /*
     * nwv_error_t BluetoothHandler::startExtendedAdvertising(int txpwr)
    {
        Utils utils;
        int err = 0;
        err = set_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0, txpwr);
        ERRCHECK((nwv_error_t)err);
        const struct bt_le_adv_param extAdvParams
        {
            .id = 0,
            .sid = 0,
            .options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME | BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED,
            .interval_min = BT_GAP_ADV_FAST_INT_MIN_2,
            .interval_max = BT_GAP_ADV_FAST_INT_MAX_2,
        };
        static struct bt_le_ext_adv_start_param extAdvStartParams
        {
            .timeout = 0,
            .num_events = 0,
        };
    
        static uint8_t mfg_data[] = {'N', 'W', 'V'}; // not sure if we need this..
        static const struct bt_data ad[] = {
            BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
            BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3),
            BT_DATA_BYTES(BT_DATA_UUID128_ALL, 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86, 0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d)};
    
        if (!extAdv)
        {
            err = bt_le_ext_adv_create(&extAdvParams, NULL, &extAdv);
            if (err)
            {
                LOG_ERR("Failed to create ext advertising set (err %d)\n", err);
            }
        }
    
        err = bt_le_ext_adv_start(extAdv, &extAdvStartParams);
    
        if (err)
        {
            if (err == -EALREADY || err == -ENOMEM)
            {
                LOG_DBG("extendet advertising already started");
                return NWV_ERROR_NONE;
            }
            LOG_ERR("Advertising failed to start (err %d)\n", err);
            return static_cast<nwv_error_t>(err);
        }
        return NWV_ERROR_NONE;
    }
    * 
    * 
    * 
    * 
    
    The reason why valid_adv_param is returning false for those options is because you need to switch to the new Advertising API to use the extended advertising options.
    
    
    struct bt_le_ext_adv *adv;
    struct bt_le_adv_param *adv_param =
    		BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE |
    				BT_LE_ADV_OPT_ONE_TIME | BT_LE_ADV_OPT_CODED |
    				BT_LE_ADV_OPT_EXT_ADV,
    				BT_GAP_ADV_FAST_INT_MIN_2,
    				BT_GAP_ADV_FAST_INT_MAX_2,
    				NULL);
    int err;
    
    err = bt_le_ext_adv_create(param, NULL, &adv);
    err = bt_le_ext_adv_start(adv, NULL);
    
    W: opcode 0x2036 status 0x01
    Failed to start advertiser (-5)
    This is telling you status 0x01 on the HCI command, which means that the controller you are trying to use do not support the extended advertising HCI commands.
    
    If you are using the zephyr controller then extended advertising is not yet supported.
    
    n hci_core.c the valid_adv_param function checks if param->options has BT_LE_ADV_OPT_EXT_ADV set.
    
    static bool valid_adv_param(const struct bt_le_adv_param *param)
    {
    	if (param->options & BT_LE_ADV_OPT_EXT_ADV) {
    		// return false;
    	}
    
    So in any case, this will cause this function to return false. It's a dependency for BT_LE_ADV_OPT_CODED though. Later on in valid_adv_ext_param it's checked again most importantly here
    
    		if (!(param->options & BT_LE_ADV_OPT_EXT_ADV) &&
    		    param->options & (BT_LE_ADV_OPT_EXT_ADV |
    				      BT_LE_ADV_OPT_NO_2M |
    				      BT_LE_ADV_OPT_CODED |
    				      BT_LE_ADV_OPT_ANONYMOUS |
    				      BT_LE_ADV_OPT_USE_TX_POWER)) {
    			 Extended options require extended advertising. 
    			return false;
    		}
    
    So basically the first function is returning even if it's a "valid" extended advertising configuration.
    
    As I mentioned earlier, it's probably on purpose until full support is available..
    
    
     */ 

    The log file with the error are

    *** Booting Zephyr OS build v3.1.99-ncs1  ***                                   
    Starting Bluetooth Central and Peripheral Heart Rate relay example              
    [00Bluetooth initialized                                                        
    Created adv: 0x20002320                                                         
    Advertiser 0x20002320 set started                                               
    Scanning started                                                                
    Advertising failed to start (err -111)                                          
    :00:00.016,540] <inf> fs_nvs: 8 Sectors of 4096 bytes                           
    [00:00:00.016,540] <inf> fs_nvs: alloc wra: 0, ed8                              
    [00:00:00.016,571] <inf> fs_nvs: data wra: 0, 244                               
    [00:00:00.016,693] <inf> sdc_hci_driver: SoftDevice Controller build revision:  
                                             f2 e7 5f 6f 23 a2 f3 e8  10 2f c3 35 9.
                                             8f 80 42 f9                            
    [00:00:00.019,744] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.019,775] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)               
    [00:00:00.019,775] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (1
    [00:00:00.020,263] <inf> bt_hci_core: No ID address. App must call settings_loa)
    [00:00:00.021,759] <err> settings: set-value failure. key: bt/name error(-2)    
    [00:00:00.022,308] <inf> bt_hci_core: Identity: DD:FB:D5:14:6F:B1 (random)      
    [00:00:00.022,338] <inf> bt_hci_core: HCI: version 5.3 (0x0c) revision 0x11a7, 9
    [00:00:00.022,338] <inf> bt_hci_core: LMP: version 5.3 (0x0c) subver 0x11a7     
    [00:00:00.033,905] <wrn> bt_hci_core: opcode 0x2039 status 0x09                 
    [00:00:00.033,935] <err> bt_adv: Failed to start advertiser                     
    Connected: FC:72:B1:18:87:7A (random)                                           
    Connected: FC:72:B1:18:87:7A (random), tx_phy 4, rx_phy 4                       
    Security changed: FC:72:B1:18:87:7A (random) level 2                            
    [00:00:00.464,508] <inf> hrs: HRS notifications enabled                         
    Disconnected: FC:72:B1:18:87:7A (random) (reason 8)                             
    [00:00:09.465,850] <inf> hrs: HRS notifications disabled                        
    Filters matched. Address: FC:72:B1:18:87:7A (random) connectable: yes           
    Connection pending                                                              
    Connected: FC:72:B1:18:87:7A (random)                                           
    Connected: FC:72:B1:18:87:7A (random), tx_phy 4, rx_phy 4                       
    Security changed: FC:72:B1:18:87:7A (random) level 2                            
    [00:00:34.125,701] <inf> hrs: HRS notifications enabled                         
    The discovery procedure succeeded                                               
    Heart Rate Sensor body location: Chest    
    

    And the log with the error of the second device is:

    And this is the log of the second device.
    Connected: DD:FB:D5:14:6F:B1 (random)                                           
    Connected: DD:FB:D5:14:6F:B1 (random), tx_phy 4, rx_phy 4                       
    Security changed: DD:FB:D5:14:6F:B1 (random) level 2                            
    [00:00:00.365,173] <inf> hrs: HRS notifications enabled                         
    Disconnected: DD:FB:D5:14:6F:B1 (random) (reason 8)                             
    [00:05:16.861,389] <inf> hrs: HRS notifications disabled                        
    Filters matched. Address: DD:FB:D5:14:6F:B1 (random) connectable: yes           
    Connection pending                                                              
    Connected: DD:FB:D5:14:6F:B1 (random)                                           
    Connected: DD:FB:D5:14:6F:B1 (random), tx_phy 4, rx_phy 4                       
    Security changed: DD:FB:D5:14:6F:B1 (random) level 2                            
    [00:05:44.700,408] <inf> hrs: HRS notifications enabled                         
    *** Booting Zephyr OS build v3.1.99-ncs1  ***                                   
    Starting Bluetooth Central and Peripheral Heart Rate relay example              
    [Bluetooth initialized                                                          
    Created adv: 0x20002320                                                         
    Advertiser 0x20002320 set started                                               
    Scanning started                                                                
    Advertising failed to start (err -111)                                          
    00:00:00.016,693] <inf> fs_nvs: 8 Sectors of 4096 bytes                         
    [00:00:00.016,723] <inf> fs_nvs: alloc wra: 0, e50                              
    [00:00:00.016,723] <inf> fs_nvs: data wra: 0, 294                               
    [00:00:00.016,845] <inf> sdc_hci_driver: SoftDevice Controller build revision:  
                                             f2 e7 5f 6f 23 a2 f3 e8  10 2f c3 35 9.
                                             8f 80 42 f9                            
    [00:00:00.019,866] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.019,897] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)               
    [00:00:00.019,927] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (1
    [00:00:00.020,385] <inf> bt_hci_core: No ID address. App must call settings_loa)
    [00:00:00.023,773] <inf> bt_hci_core: Identity: FC:72:B1:18:87:7A (random)      
    [00:00:00.023,773] <inf> bt_hci_core: HCI: version 5.3 (0x0c) revision 0x11a7, 9
    [00:00:00.023,803] <inf> bt_hci_core: LMP: version 5.3 (0x0c) subver 0x11a7     
    [00:00:00.035,705] <wrn> bt_hci_core: opcode 0x2039 status 0x09                 
    [00:00:00.035,705] <err> bt_adv: Failed to start advertiser                     
    Connected: DD:FB:D5:14:6F:B1 (random)                                           
    Connected: DD:FB:D5:14:6F:B1 (random), tx_phy 4, rx_phy 4                       
    Security changed: DD:FB:D5:14:6F:B1 (random) level 2                            
    [00:00:00.870,788] <inf> hrs: HRS notifications enabled             

  • Do you enable and call settings_load()? (from the code I see you call it if CONFIG_SETTINGS is set but I don't know if that is the case in your project configuration).

  • Sorry for delay 

    CONFIG_SETTING=y 

    see prj.config

    #CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_HR"
    CONFIG_BT_DEVICE_APPEARANCE=832
    CONFIG_BT_MAX_CONN=2
    CONFIG_BT_MAX_PAIRED=2
    CONFIG_BT_USER_PHY_UPDATE=y
    CONFIG_BT_DEBUG_LOG=y
    CONFIG_BT_SMP=y
    
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    
    CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_GATT_DM=y
    
    CONFIG_BT_HRS=y
    CONFIG_BT_HRS_CLIENT=y
    
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    CONFIG_DK_LIBRARY=y
    
    
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    
    CONFIG_BT_CTLR_ADV_EXT=y
    CONFIG_BT_CTLR_PHY_CODED=y
    
    CONFIG_BT_EXT_ADV=y
    CONFIG_BT_USER_PHY_UPDATE=y
    
    CONFIG_BT_PERIPHERAL=y
    ##### ATTENZIONE AGGIUNGO GLI ADVETIZER EXTENDED
    CONFIG_BT_EXT_ADV=y
    CONFIG_BT_CTLR_ADV_EXT=y
    # BO AGGIUNTO DA PROVARE
    CONFIG_BT_CTLR_ADV_EXT=y
    CONFIG_BT_EXT_ADV=y
    CONFIG_BT_CTLR_PHY_CODED=y
    CONFIG_BT_USER_PHY_UPDATE=y
    CONFIG_BT_EXT_ADV_LEGACY_SUPPORT=y
    CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
    CONFIG_BT_CTLR_ADV_SET=2
    CONFIG_BT_CTLR_ADV_AUX_SET=2
    CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
    CONFIG_BT_USER_PHY_UPDATE=y
    
    # Link Layer NORDIC ONLY SUPPORTED
    #CONFIG_BT_LL_NRFXLIB_VS_INCLUDE=y
    #CONFIG_BT_LL_NRFXLIB_DEFAULT=y

  • Hi,

    I don't see anything obviously wrong here (other than many duplicated configs and that both the code and prj.conf could need a cleanup, which in itself could make it easier to spot things).

    However, according to the API documentation bt_le_adv_start() will return -ECONNREFUSED (-111) in a specific case - when the maximum number of connections is reached, which may be what you are seeing:

     * @return -ECONNREFUSED When connectable advertising is requested and there
     *                       is already maximum number of connections established
     *                       in the controller.
     *                       This error code is only guaranteed when using Zephyr
     *                       controller, for other controllers code returned in
     *                       this case may be -EIO.

Related