<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>BLE Bonding after power cycle</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119834/ble-bonding-after-power-cycle</link><description>Product: nRF54L15DK, SDK V2.9.0 
 Application: Multi protocol (BLE + Matter/Thread) Door Lock 
 Issue: BLE bonding is not retained after power cycles. The mobile app requests pairing (pop-up window) confirmation from the user. 
 Hi, 
 This can be a extension</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 Mar 2025 12:43:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119834/ble-bonding-after-power-cycle" /><item><title>RE: BLE Bonding after power cycle</title><link>https://devzone.nordicsemi.com/thread/528405?ContentTypeID=1</link><pubDate>Fri, 21 Mar 2025 12:43:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47825185-7f37-42e8-aebe-04febc8b41a5</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Subu,&amp;nbsp;&lt;br /&gt;I&amp;#39;m not so familiar with the Matter code so I don&amp;#39;t have an idea what could be wrong. But you may have to step into the code and check whty NOMEM is returned.&amp;nbsp;&lt;br /&gt;There could be an issue on the configuration of the Bluetooth ID.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I quote here an answer from one of my colleague. She made a sample for this, the code following&amp;nbsp;is provided as is.&amp;nbsp;&lt;br /&gt;======&lt;/p&gt;
&lt;p&gt;Matter uses an advertising arbiter, which manually sets the Bluetooth ID for the advertisement set to be that of the Matter Bluetooth services ID (&lt;a href="https://github.com/nrfconnect/sdk-connectedhomeip/blob/v2.6.1/src/platform/Zephyr/BLEAdvertisingArbiter.cpp#L63"&gt;BLEAdvertisingArbiter.cpp#L63&lt;/a&gt;). This arbiter does not provide support for using extended advertisement with multiple advertisement sets.&lt;/p&gt;
&lt;p&gt;I have discussed this with the developers, who agreed that the best solution would be to pass the Bluetooth ID as part of an advertising request structure to the InsertRequest() method. You can see an example usage of the InsertRequest() method in the NUSService::Init() and NusService:StartServer() functions in the Matter NUS service (&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.6.1/samples/matter/common/src/bt_nus/bt_nus_service.cpp#L47-L106"&gt;bt_nus_service.cpp#L47-L106&lt;/a&gt;). However, this requires changing the Matter SDK files, which I would normally not recommend. The developers are looking into addressing this issue, but I cannot comment on the schedule since this needs to be prioritized against other tasks.&lt;/p&gt;
&lt;p&gt;In the meantime, one option is not to use the arbiter; instead, you can handle the advertisement yourself directly in the service using the extended advertisement API.&lt;br /&gt;For bonding and extended advertisement, the following configurations must be set&lt;/p&gt;
&lt;p&gt;You need to set the following in prj.conf:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_BT_BONDABLE=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
CONFIG_BT_SETTINGS=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Additionally, you should create a config called BT_ID_MAX in the project Kconfig file and set the default value to 2.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;config BT_ID_MAX
	default 2&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;For the code itself, using the NUS service as an example, you would have to replace parts of bt_nus_service.cpp. The following code should create an advertisement set for Bluetooth ID 0, which supports bonding:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define MATTER_NUS_DEVICE_NAME &amp;quot;MatterNUS&amp;quot;
static struct bt_le_ext_adv *nus_adv;

static struct bt_le_adv_param nus_adv_param = {
	.id = BT_ID_DEFAULT,
	.options = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_USE_NAME,
	.interval_min = BT_GAP_ADV_FAST_INT_MIN_2, /* 100 ms */
	.interval_max = BT_GAP_ADV_FAST_INT_MAX_2, /* 150 ms */
};

static const struct bt_data nus_ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
};

static int nus_advertise()
{
	int err;
	struct bt_le_ext_adv_start_param ext_adv_start_param = {0};

	err = bt_set_name(MATTER_NUS_DEVICE_NAME);
	if (err) {
		LOG_ERR(&amp;quot;Failed to set device name (err %d)&amp;quot;, err);
		return err;
	}

	err = bt_le_ext_adv_create(&amp;amp;nus_adv_param, NULL, &amp;amp;nus_adv);

	if (err) {
		LOG_ERR(&amp;quot;Failed to create advertising data (err %d)&amp;quot;, err);
		return err;
	}
	
	err = bt_le_ext_adv_set_data(nus_adv, nus_ad, ARRAY_SIZE(nus_ad),
				     NULL, 0);
	if (err) {
		LOG_ERR(&amp;quot;Failed to set advertising data (err %d)&amp;quot;, err);
		return err;
	}

	return bt_le_ext_adv_start(nus_adv, &amp;amp;ext_adv_start_param);
}&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This code is not thoroughly tested or qualified and should be considered provided “as-is”. I have tested that this works with bonding by calling advertising_set_create() instead of InsertRequest() in StartServer(). There are still some issues with the code, and it does not play well with the Matter Bluetooth services right now, but I hope it can help as a starting point.&lt;/p&gt;
&lt;p&gt;I also recommend looking at the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.6.1/nrf/samples/bluetooth/multiple_adv_sets/README.html"&gt;Bluetooth: Multiple advertising sets&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to see how the extended advertisement API is used there.&lt;br /&gt;&lt;br /&gt;====&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Bonding after power cycle</title><link>https://devzone.nordicsemi.com/thread/528263?ContentTypeID=1</link><pubDate>Thu, 20 Mar 2025 15:10:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69a2ca4b-c9b1-494c-9d6c-4c9d12a5d3b7</guid><dc:creator>SubuMuthu</dc:creator><description>&lt;p&gt;Hi Huang Bui,&lt;/p&gt;
&lt;p&gt;Thanks for the answers.&lt;/p&gt;
&lt;p&gt;On #2,&amp;nbsp;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;we do not&amp;nbsp; have any IO capabilities in the product. The BLE is the only means of connection.&lt;/li&gt;
&lt;li&gt;When the customer installs the product or wants to configure the product, BLE/mobile app is used.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The (&amp;quot;custom&amp;quot;) BLE is always active. Event if it is shutdown, it will be temporary.&lt;/li&gt;
&lt;li&gt;BLE is also used to start the Matter commissioner (which will start the Matter BLE services).&amp;nbsp; This is one of the reason for me to use the Matter Arbiter.&amp;nbsp;
&lt;ol&gt;
&lt;li&gt;After BLE&amp;nbsp; initiate the Matter commissioner, the product joins the Matter/Thread network and expect to work&amp;nbsp; &amp;nbsp;with Matter/Thread and also with the&amp;nbsp; &amp;quot;custom&amp;quot; BLE service.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have implemented the extended BLE advertisement as you recommended but the Matter commissioner does not start. To summarize,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;BLE stack is initialized, advertises and connects to mobile. Mobile performs the initial configuration and then, sends a custom message to the lock to start the Matter commissioner.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The matter commissioning fails. I have&amp;nbsp; disconnected the BLE connection before&amp;nbsp; starting the matter commissioner , stopped the Advertisement and it does not help!&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
Starting Matter Commissioner 
I: 4967 [DIS]Updating services using commissioning mode 1
E: 4972 [DIS]Failed to remove advertised services: 3
I: 4977 [DIS]Advertise commission parameter vendorID=65521 productID=32774 discriminator=3840/15 cm=1 cp=0
E: 4986 [DIS]Failed to advertise commissionable node: 3
E: 4991 [DIS]Failed to finalize service update: 3
E: No valid legacy adv
E: 4998 [DL]Failed to start CHIPoBLE advertising: -12
I: 5002 [DL]CHIPoBLE advertising already stopped
E: 5007 [DL]Could not start CHIPoBLE service due to error: 200000c&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The above was tested using Matter Door lock sample. The error code -12 indicates ENOM - out of memory.&amp;nbsp; Do I need to&amp;nbsp; increase stack size?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Bonding after power cycle</title><link>https://devzone.nordicsemi.com/thread/528253?ContentTypeID=1</link><pubDate>Thu, 20 Mar 2025 14:24:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbf7ba1f-fe4d-4642-8c1a-6c2492ddac80</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Subu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see a problem with approach #1. You can also implement a timer, if after a certain time the link it not secured with level 2 , you can terminate the connection. To remove only one bond you can use&amp;nbsp;&lt;span&gt;bt_unpair(). You can specify the exact&amp;nbsp;address&amp;nbsp;you want to unbond. I believe the function will also terminate the connection.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Please give more info on issue #2. You plan to add the Matter BLE service after the link is secured&amp;nbsp; ? My suggestion is to instead make sure the service has been configured to require encryption (security level 2 and up). You can be sure that it will only be accessible if the link is encrypted. Then you can have the timer. It&amp;#39;s better than dynamically add and remove services which is more complicated and may not be supported by the peer ( to rediscover the attribute table).&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Bonding after power cycle</title><link>https://devzone.nordicsemi.com/thread/528094?ContentTypeID=1</link><pubDate>Wed, 19 Mar 2025 22:35:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df594c7c-7ada-4fa7-8ce2-4430722375ee</guid><dc:creator>SubuMuthu</dc:creator><description>&lt;p&gt;H Hung Bui,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It works and i am able to verify it in my application.&amp;nbsp; Appreciate the quick response.&lt;/p&gt;
&lt;p&gt;Two more questions:&lt;/p&gt;
&lt;p&gt;#1.&lt;/p&gt;
&lt;p&gt;Sometime, the security level is not reached (I set&amp;nbsp; Level 2:&amp;nbsp; Unauthenticated pairing, and only Security level of 1 is reached). When it happens, the BLE connection is not terminated and both Lock and the App remain connected till the App disconnects. This is not good for us and we would like the BLE connection to&amp;nbsp; terminate and restart.&lt;/p&gt;
&lt;p&gt;What is the best way to restart the advertisement? I have implemented the below.&lt;/p&gt;
&lt;p&gt;1. In security_changed call back, detect the error aka if the level is 1 or not.&lt;/p&gt;
&lt;p&gt;2. If the level is 1,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- remove the bond (is there a way to remove the current bond only, preserving the rest?).&lt;/p&gt;
&lt;p&gt;- unref the current connection.&lt;/p&gt;
&lt;p&gt;- initiate a disconnect.&lt;/p&gt;
&lt;p&gt;- restart the adv.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is there a better way to do this? Sometimes, the app and lock reconnect, but the security level is not reached and it goes through repeated disconnect -&amp;gt; connect -&amp;gt; fail loop.&lt;/p&gt;
&lt;p&gt;#2.&lt;/p&gt;
&lt;p&gt;When Matter&amp;#39;s BLE service is started, will there be an issue since Matter BLE is handled by Arbiter which gives priority to Matter BLE service. we plan to start and stop the Matter BLE service.&lt;/p&gt;
&lt;p&gt;Subu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Bonding after power cycle</title><link>https://devzone.nordicsemi.com/thread/527622?ContentTypeID=1</link><pubDate>Mon, 17 Mar 2025 12:48:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ed49a6f-a8ea-499c-80cc-401c72f4baa5</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Subu Muthu,&amp;nbsp;&lt;br /&gt;If you take a look at this ticket:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/113635/adding-custom-ble-services-to-matter/496851"&gt;RE: Adding custom BLE services to Matter&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can find that &amp;quot;&lt;span&gt;Bonding cannot be enabled for Matter BLE services, as this makes it non-compliant with the Matter specification due to the requirement that a static random address shall be used for Matter BLE service advertising purposes.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So when you reset your device the address (static random address) will be changed and the phone won&amp;#39;t be able to detect the board as previously bonded and will make a new bond as you already noticed.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;One option to solve the issue is&amp;nbsp;not to use the Matter&amp;#39;s arbiter; instead, you can handle the advertisement yourself directly in the service using the extended advertisement API. You would need to create one extra Bluetooth ID and use this Bluetooth ID to do advertising with the address that the peer can recognize (either static address or resolvable random address.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>