<?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>Limit HIDs max client count</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119404/limit-hids-max-client-count</link><description>Hello and thank you for reading. We are using SDK 2.5.0 and the nrf5340, and would appreciate some help with the HID over Gatt functionality. 
 Our device implements multiple services, including NUS and HID over GATT. We are now experimenting with having</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 03 Mar 2025 15:09:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119404/limit-hids-max-client-count" /><item><title>RE: Limit HIDs max client count</title><link>https://devzone.nordicsemi.com/thread/525560?ContentTypeID=1</link><pubDate>Mon, 03 Mar 2025 15:09:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e86f16f6-2b80-476d-9060-60ae7a77b394</guid><dc:creator>i_4556</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for your reply, and especially for clarifying the functionality of &lt;em&gt;&lt;strong&gt;CONFIG_BT_HIDS_MAX_CLIENT_COUNT.&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Your example code unfortunately isnt quite what Im looking for; I dont want to disconnect the first device when the second connects, I simply want to refuse the subscription request from the second device if the first one is still subscribed.&lt;/p&gt;
&lt;p&gt;I notice that the callback when the CCC changes doesnt directly allow for this implementation, as I cannot get the subscriber&amp;#39;s address/conn* from it, nor can I return false or something to reject the subscription. Is there some other implementation, perhaps with a different callback, I could use instead?&lt;/p&gt;
&lt;p&gt;EDIT: Im thinking I could do something with a custom implementation of CCC_write, seeing as that function _does_ get the conn object, but I seem to be doing something wrong somehow...&lt;/p&gt;
&lt;p&gt;I changed my service declaration to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;BT_GATT_SERVICE_DEFINE(
	Amber_spp_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_AMBER_SPP),
	BT_GATT_CHARACTERISTIC(PADDING_UUID,NULL,NULL, NULL, NULL, NULL),  //For some reason if i erase this characteristic, it doesnt notify anymore
	
	BT_GATT_CHARACTERISTIC(BT_UUID_AMBER_SPP_RX, BT_GATT_CHRC_WRITE, BT_GATT_PERM_WRITE, NULL,rx_data, NULL),
	
	BT_GATT_CHARACTERISTIC(BT_UUID_AMBER_SPP_TX, BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_NONE, NULL,NULL, NULL),

	BT_GATT_DESCRIPTOR(BT_UUID_GATT_CCC,BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,bt_gatt_attr_read_ccc,my_cfg_write,NULL),
	
);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And I can see in the console my on-write callback is triggering and _should_ be enabling notifications, but then I never actually get my notification.&lt;/p&gt;
&lt;p&gt;Does this approach make sense, is there something obvious im doing wrong?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT2: actually the more I think about it, the more I think it makes sense to just, on the HID characterisitc, use bt_gatt_notify but instead of NULL, I will pass the conn* of the first/desired peer so that only they get the update. Does that make sense, so technically both clients have notifications enabled but only one actually gets anything. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Limit HIDs max client count</title><link>https://devzone.nordicsemi.com/thread/525274?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 12:48:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4ced4b2-333b-454d-94ab-bfafd2913550</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The &lt;em&gt;&lt;strong&gt;CONFIG_BT_HIDS_MAX_CLIENT_COUNT &lt;/strong&gt;&lt;/em&gt;configuration determines the maximum number of HID clients that can be tracked by the HID service instance. Setting this value to 1 means the HID service will maintain context for only one client. However, this does not inherently prevent multiple devices from connecting or subscribing to the HID service; it merely limits the internal tracking to a single client. Therefore, additional application-level logic is necessary to enforce the desired subscription behavior. You can handle the connection and disconnection behavior as your application need. Based on your description you can do something like this (for example).. There are many ways to do this, but the point here is that you cannot just rely on&amp;nbsp;&lt;em&gt;&lt;strong&gt;CONFIG_BT_HIDS_MAX_CLIENT_COUNT&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void connected(struct bt_conn *conn, uint8_t err)
{
    if (err) {
        LOG_ERR(&amp;quot;Connection failed (err %d)&amp;quot;, err);
        return;
    }

    // Disconnect the old connection , if I understood your text right, this is what you want?
    if (centrals[0].conn) {
        LOG_WRN(&amp;quot;New connection detected! Disconnecting previous device.&amp;quot;);
        bt_conn_disconnect(centrals[0].conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
        bt_conn_unref(centrals[0].conn);
    }

    centrals[0].conn = bt_conn_ref(conn);
    centrals[0].subscribed_nus = false;
    centrals[0].subscribed_hid = false;
    LOG_INF(&amp;quot;New device connected, old device disconnected.&amp;quot;);
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
    if (centrals[0].conn == conn) {
        LOG_INF(&amp;quot;Device disconnected, clearing connection context.&amp;quot;);
        if (centrals[0].subscribed_hid) {
            hid_active_conn = NULL; 
        }
        bt_conn_unref(centrals[0].conn);
        centrals[0].conn = NULL;
        centrals[0].subscribed_nus = false;
        centrals[0].subscribed_hid = false;
    }
}

BT_CONN_CB_DEFINE(conn_callbacks) = {
    .connected = connected,
    .disconnected = disconnected,
};&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>