<?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>Received empty data array after notification</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119515/received-empty-data-array-after-notification</link><description>Hi, 
 I adapted the nus_client from the Nordic Connect SDK v2.7.0. I changed the UUID and some function names, but in general the code stays the same. I can subscribe one of the characteristics and receive data from it. But the problem is, that everytime</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Apr 2025 09:57:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119515/received-empty-data-array-after-notification" /><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/530191?ContentTypeID=1</link><pubDate>Wed, 02 Apr 2025 09:57:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b97f3c6d-65b5-4444-9d99-117d398a701c</guid><dc:creator>ilockit_CFR</dc:creator><description>&lt;p&gt;Indeed, there was a path in the callback which returned zero. Now, everything works as expected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for the support.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/530066?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 18:17:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b29f8d0-e5a1-4542-8c2d-6e4caa263077</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;And there is the location for your BT_GATT_ITER_STOP return value, passed from from the callback function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;      return BT_GATT_ITER_STOP;
	}

	
	if (ili-&amp;gt;cb.received) {
	/** vvvvvv--- BT_GATT_ITER_STOP value is ZERO     **/
		return ili-&amp;gt;cb.received(ili, data, length);
	}

	return BT_GATT_ITER_CONTINUE;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Pretty sure that your callback function returns zero, which is the value of BT_GATT_ITER_STOP. Try putting a LOG_DBG statement in there.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/529950?ContentTypeID=1</link><pubDate>Tue, 01 Apr 2025 10:49:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:067b2e17-a49d-4e9e-b844-7c0d7c8227ed</guid><dc:creator>ilockit_CFR</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;here are the corresponding parts of the central code:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint8_t on_received(struct bt_conn *conn,
			struct bt_gatt_subscribe_params *params,
			const void *data, uint16_t length)
{
	struct bt_ili_client *ili;

	/* Retrieve ILI Client module context. */
	ili = CONTAINER_OF(params, struct bt_ili_client, mode_notif_params);

	LOG_DBG(&amp;quot;[NOTIFICATION] data %p length %u&amp;quot;, data, length);
	
	if (!data) {
		LOG_DBG(&amp;quot;[UNSUBSCRIBED]&amp;quot;);
		params-&amp;gt;value_handle = 0;
		atomic_clear_bit(&amp;amp;ili-&amp;gt;state, ILI_C_MODE_NOTIF_ENABLED);
		if (ili-&amp;gt;cb.unsubscribed) {
			ili-&amp;gt;cb.unsubscribed(ili);
		}
		return BT_GATT_ITER_STOP;
	}

	
	if (ili-&amp;gt;cb.received) {
		return ili-&amp;gt;cb.received(ili, data, length);
	}

	return BT_GATT_ITER_CONTINUE;
}

int bt_ili_client_init(struct bt_ili_client *ili_c,
		       const struct bt_ili_client_init_param *ili_c_init)
{
	if (!ili_c || !ili_c_init) {
		return -EINVAL;
	}

	if (atomic_test_and_set_bit(&amp;amp;ili_c-&amp;gt;state, ILI_C_INITIALIZED)) {
		return -EALREADY;
	}

	memcpy(&amp;amp;ili_c-&amp;gt;cb, &amp;amp;ili_c_init-&amp;gt;cb, sizeof(ili_c-&amp;gt;cb));

	return 0;
}

int bt_ili_handles_assign(struct bt_gatt_dm *dm,
			  struct bt_ili_client *ili_c)
{
	const struct bt_gatt_dm_attr *gatt_service_attr =
			bt_gatt_dm_service_get(dm);
	const struct bt_gatt_service_val *gatt_service =
			bt_gatt_dm_attr_service_val(gatt_service_attr);
	const struct bt_gatt_dm_attr *gatt_chrc;
	const struct bt_gatt_dm_attr *gatt_desc;

	if (bt_uuid_cmp(gatt_service-&amp;gt;uuid, BT_UUID_ILI_C_SERVICE)) {
		return -ENOTSUP;
	}
	LOG_DBG(&amp;quot;Getting handles from service.&amp;quot;);
	memset(&amp;amp;ili_c-&amp;gt;handles, 0xFF, sizeof(ili_c-&amp;gt;handles));

	/* ILI mode Characteristic */
	gatt_chrc = bt_gatt_dm_char_by_uuid(dm, BT_UUID_ILI_C_MODE);
	if (!gatt_chrc) {
		LOG_ERR(&amp;quot;Missing mode characteristic.&amp;quot;);
		return -EINVAL;
	}
	/* ILI mode Characteristic */
	gatt_desc = bt_gatt_dm_desc_by_uuid(dm, gatt_chrc, BT_UUID_ILI_C_MODE);
	if (!gatt_desc) {
		LOG_ERR(&amp;quot;Missing mode value descriptor in characteristic.&amp;quot;);
		return -EINVAL;
	}
	LOG_DBG(&amp;quot;Found handle for mode characteristic.&amp;quot;);
	ili_c-&amp;gt;handles.mode = gatt_desc-&amp;gt;handle;
	/* ILI mode CCC */
	gatt_desc = bt_gatt_dm_desc_by_uuid(dm, gatt_chrc, BT_UUID_GATT_CCC);
	if (!gatt_desc) {
		LOG_ERR(&amp;quot;Missing mode CCC in characteristic.&amp;quot;);
		return -EINVAL;
	}
	LOG_DBG(&amp;quot;Found handle for CCC of mode characteristic.&amp;quot;);
	ili_c-&amp;gt;handles.mode_ccc = gatt_desc-&amp;gt;handle;

	/* serial Characteristic */
	gatt_chrc = bt_gatt_dm_char_by_uuid(dm, BT_UUID_ILI_C_SERIAL);
	if (!gatt_chrc) {
		LOG_ERR(&amp;quot;Missing serial characteristic.&amp;quot;);
		return -EINVAL;
	}
	/* ILI serial */
	gatt_desc = bt_gatt_dm_desc_by_uuid(dm, gatt_chrc, BT_UUID_ILI_C_SERIAL);
	if (!gatt_desc) {
		LOG_ERR(&amp;quot;Missing serial value descriptor in characteristic.&amp;quot;);
		return -EINVAL;
	}
	LOG_DBG(&amp;quot;Found handle for serial characteristic.&amp;quot;);
	ili_c-&amp;gt;handles.serial = gatt_desc-&amp;gt;handle;

	/* Assign connection instance. */
	ili_c-&amp;gt;conn = bt_gatt_dm_conn_get(dm);
	return 0;
}

int bt_ili_subscribe_mode(struct bt_ili_client *ili_c)
{
	int err;

	if (atomic_test_and_set_bit(&amp;amp;ili_c-&amp;gt;state, ILI_C_MODE_NOTIF_ENABLED)) {
		return -EALREADY;
	}

	ili_c-&amp;gt;mode_notif_params.notify = on_received;
	ili_c-&amp;gt;mode_notif_params.value = BT_GATT_CCC_NOTIFY;
	ili_c-&amp;gt;mode_notif_params.value_handle = ili_c-&amp;gt;handles.mode;
	ili_c-&amp;gt;mode_notif_params.ccc_handle = ili_c-&amp;gt;handles.mode_ccc;
	atomic_set_bit(ili_c-&amp;gt;mode_notif_params.flags,
		       BT_GATT_SUBSCRIBE_FLAG_VOLATILE);

	err = bt_gatt_subscribe(ili_c-&amp;gt;conn, &amp;amp;ili_c-&amp;gt;mode_notif_params);
	if (err) {
		LOG_ERR(&amp;quot;Subscribe to mode characteristic failed (err %d)&amp;quot;, err);
		atomic_clear_bit(&amp;amp;ili_c-&amp;gt;state, ILI_C_MODE_NOTIF_ENABLED);
	} else {
		LOG_DBG(&amp;quot;[SUBSCRIBED] mode characteristic&amp;quot;);
	}

	return err;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And here is the part where I subscribe the characteristic in my application:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
static void discovery_completed_cb(struct bt_gatt_dm *dm,
				   void *context)
{
	int err;

	LOG_DBG(&amp;quot;The discovery procedure succeeded&amp;quot;);

	bt_gatt_dm_data_print(dm);

	err = bt_ili_handles_assign(dm, &amp;amp;m_ili_fob);
	if (err) {
		LOG_DBG(&amp;quot;Could not init BAS client object, error: %d&amp;quot;, err);
	}

    err = bt_ili_subscribe_mode(&amp;amp;m_ili_fob);
	if (err) {
		LOG_DBG(&amp;quot;Cannot subscribe to ILI mode value notification &amp;quot;
			&amp;quot;(err: %d)&amp;quot;, err);
		/* Continue anyway */
	}
	
	err = bt_gatt_dm_data_release(dm);
	if (err) {
		LOG_DBG(&amp;quot;Could not release the discovery data, error &amp;quot;
		       &amp;quot;code: %d&amp;quot;, err);
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/529393?ContentTypeID=1</link><pubDate>Thu, 27 Mar 2025 22:42:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51111999-ee4b-4e9b-996a-e41c722021d0</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Could you post the code that handles the notifications on the central side?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/529207?ContentTypeID=1</link><pubDate>Thu, 27 Mar 2025 07:25:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54b5a0fc-b707-403d-b86a-b50416de505f</guid><dc:creator>ilockit_CFR</dc:creator><description>&lt;p&gt;Thanks for the reply. I tried it again with your instructions and received this:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6874.keyfob_5F00_unsubscribe.pcapng"&gt;devzone.nordicsemi.com/.../6874.keyfob_5F00_unsubscribe.pcapng&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/528836?ContentTypeID=1</link><pubDate>Tue, 25 Mar 2025 12:24:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a6b9c84-74de-42ad-b589-eda6387c6e4e</guid><dc:creator>Sigurd</dc:creator><description>[quote user="ilockit_CFR"]I attached the wireshark file for the connection.[/quote]
&lt;p&gt;unfortunately, the connection is encrypted, and the sniffer did not have the keys, so could not read much from that log.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1742905376206v1.png" alt=" " /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/nrfutil/page/nrfutil-ble-sniffer/guides/common_actions_sniffing_conn_bonded_devs.html"&gt;https://docs.nordicsemi.com/bundle/nrfutil/page/nrfutil-ble-sniffer/guides/common_actions_sniffing_conn_bonded_devs.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://docs.nordicsemi.com/bundle/nrfutil/page/nrfutil-ble-sniffer/guides/common_actions_sniffing_pairing_procedure.html"&gt;https://docs.nordicsemi.com/bundle/nrfutil/page/nrfutil-ble-sniffer/guides/common_actions_sniffing_pairing_procedure.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/526961?ContentTypeID=1</link><pubDate>Wed, 12 Mar 2025 13:56:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7040780-1fe1-4fbc-b82f-e7ee2515e751</guid><dc:creator>ilockit_CFR</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the only place where BT_GATT_ITER_STOP is returned is when the [UNSUBSCRIBE] happens. I attached the wireshark file for the connection.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/keyfob_5F00_unsubscribe.pcapng"&gt;devzone.nordicsemi.com/.../keyfob_5F00_unsubscribe.pcapng&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At the same time these were the logs of the peripheral:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;00&amp;gt; D: Connecting (0)
00&amp;gt; I: Connected
00&amp;gt; 
00&amp;gt; D: Security changed: E7:B8:CB:8B:91:F8 (random) level 2
00&amp;gt; D: The discovery procedure succeeded
00&amp;gt; D: Getting handles from service.
00&amp;gt; D: Found handle for mode characteristic.
00&amp;gt; D: Found handle for CCC of mode characteristic.
00&amp;gt; D: Found handle for serial characteristic.
00&amp;gt; D: [SUBSCRIBED] mode characteristic
00&amp;gt; D: [NOTIFICATION] data 0x2000e34c length 4
00&amp;gt; D: ble_mode_data_received
00&amp;gt; data: 01000000
00&amp;gt; D: [NOTIFICATION] data 0 length 0
00&amp;gt; D: [UNSUBSCRIBED]
00&amp;gt; D: ble_mode_unsubscribed
00&amp;gt; D: [SUBSCRIBED] mode characteristic
00&amp;gt; D: [NOTIFICATION] data 0x2000e34c length 4
00&amp;gt; D: ble_mode_data_received
00&amp;gt; data: 00000000
00&amp;gt; D: [NOTIFICATION] data 0 length 0
00&amp;gt; D: [UNSUBSCRIBED]
00&amp;gt; D: ble_mode_unsubscribed
00&amp;gt; D: [SUBSCRIBED] mode characteristic&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;At the moment I use a workaround and subscribe everytime when the characteristic gets unsubscribed. This is why there are more than one [SUBSCRIBED] messages.&lt;/p&gt;
&lt;p&gt;I hope this helps.&lt;/p&gt;
&lt;p&gt;Christian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/525782?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 15:43:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91cc062b-f440-497b-bb27-f5ec44e2dced</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Triple-check the return code of your notification function. A return value of BT_GATT_ITER_STOP will automagically unsubscribe!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Received empty data array after notification</title><link>https://devzone.nordicsemi.com/thread/525775?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 15:23:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:375325e4-46a8-4836-87cd-a75de30391bb</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Could you capture a sniffer trace, so we can see what&amp;#39;s happening on-the-air ?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.nordicsemi.com/Products/Development-tools/nrf-sniffer-for-bluetooth-le"&gt;https://www.nordicsemi.com/Products/Development-tools/nrf-sniffer-for-bluetooth-le&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>