<?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>How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/88773/how-shall-i-define-multiple-services-in-gatt-server-database-so-that-only-1-service-is-seen-by-gatt-client-at-a-time</link><description>I am developing GATT Server Reader Firmware usng nRF SDK COnnect using NRF52840 
 
 I have implemented two services in reader FW in two files say: service_a.c and service_b.c 
 Both files have their respective GATT attribute table. 
 Both have their advertisement</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jun 2022 07:49:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/88773/how-shall-i-define-multiple-services-in-gatt-server-database-so-that-only-1-service-is-seen-by-gatt-client-at-a-time" /><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/374676?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 07:49:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5afc79d1-136f-45c2-9df7-c9e829626813</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Deep Patel,&amp;nbsp;&lt;br /&gt;If you search for &amp;quot;zephyr disconnect ble&amp;quot; you can find &lt;a href="https://docs.zephyrproject.org/2.6.0/reference/bluetooth/connection_mgmt.html"&gt;this link&lt;/a&gt;&amp;nbsp;. And inside that you will find the function to disconnect:&amp;nbsp;&lt;span&gt;bt_conn_disconnect()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yes you need to have&amp;nbsp;CONFIG_BT_GATT_SERVICE_CHANGED=y to tell the peer device that it need to re-discovery the service every time it connects.&amp;nbsp;&lt;br /&gt;I would suggest to test with nRF Connect app on the phone first before you test with your own app.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/374634?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 22:16:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac22fa97-6f19-4901-b5db-9f2b57c96e0f</guid><dc:creator>Deep Patel</dc:creator><description>&lt;p&gt;Also, adding to my previous response :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot; You would need to do a service discovery every time the ATT table change. &amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How do i do this ? Isnt it already enabled / included ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also,&amp;nbsp;CONFIG_BT_GATT_SERVICE_CHANGED Kconfig is required to be enabled ?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/374613?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 17:41:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e57f9a6d-700a-4a78-9f7e-e3fd4cab0eee</guid><dc:creator>Deep Patel</dc:creator><description>&lt;p&gt;Hello Hung Bai,&lt;/p&gt;
&lt;p&gt;Thanks let me look into this. Hope that suits my requirement.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am looking for a way to implement, so that reader peripheral can disconnect any open BLE connection with Mobile Client, stop advertising and start new advertising or no advertising based on input.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;For Example :&lt;/p&gt;
&lt;p&gt;Currently, Reader is configured with value &amp;#39;1&amp;#39; and it is advertising &amp;#39;XYZ service&amp;#39;. Any mobile scanning this service can now connect.&lt;/p&gt;
&lt;p&gt;If reader gets a user input with value &amp;#39;2&amp;#39; .. i want the reader (peripheral) to disconnect with any open connections with Mobile Client, stop advertising &amp;#39;XYZ service&amp;#39; and start advertising &amp;#39;ABC service&amp;#39;&lt;/p&gt;
&lt;p&gt;Similarly,&amp;nbsp;&lt;span&gt;If reader gets a user input with value &amp;#39;0&amp;#39; .. i want the reader (peripheral) to disconnect with any open connection with Mobile Client, stop advertising &amp;#39;XYZ service&amp;#39; and be idle (no advertisements)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/374578?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 14:16:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45d320a4-0658-4b05-96c6-be71b6324041</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Deep Patel,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please find the attached example.&amp;nbsp; It based on the LBS example in SDK v2.0.0 . When you press button 2&amp;nbsp; on the DK it will register a new service. And when you press button 3 on the DK it will remove the service. You would need to do a service discovery every time the ATT table change.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;It&amp;#39;s pretty simple actually, simply calling&amp;nbsp;&lt;span&gt;bt_gatt_service_register() and&amp;nbsp;bt_gatt_service_unregister() to add and remove service.&amp;nbsp;&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/peripheral_5F00_lbs_5F00_dynamic.zip"&gt;devzone.nordicsemi.com/.../peripheral_5F00_lbs_5F00_dynamic.zip&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/373323?ContentTypeID=1</link><pubDate>Mon, 20 Jun 2022 20:27:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c250ac35-5dc8-457a-a2f1-b6233ad8671b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Deep Patel,&amp;nbsp;&lt;br /&gt;I &amp;#39;m on a business trip and will be back next week. If you need urgent support please create a new case and have a link to this. We will have other tech support to look into it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/373087?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 15:45:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73e0f934-8ec6-4ac1-9a8c-29a26b446b5c</guid><dc:creator>Deep Patel</dc:creator><description>&lt;p&gt;Thanks Hung Bui,&lt;/p&gt;
&lt;p&gt;I will try this solution.&lt;/p&gt;
&lt;p&gt;Also, can you explain if i want to try the dynamic ATT solution ?&lt;/p&gt;
&lt;p&gt;How to define the service in this case and how to implement:&lt;/p&gt;
&lt;p&gt;// Set GATT database capabilities&amp;nbsp;&lt;/p&gt;
&lt;p&gt;// Set GATT service changed = 0100FFFF&lt;/p&gt;
&lt;p&gt;I was using SiLabs BGM113 MCU earlier for our previous BLE peripheral implementation and it was easy to implement GATT service change using a variable and their SDK API.&lt;/p&gt;
&lt;p&gt;Looks complex to understand this implementation in Nordic NRF Connect SDK&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/372939?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 07:49:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4244fa7f-d5b9-4b55-a05b-2f33be62d0b4</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Deep Patel,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I meant was that you keep the declaration of different services in your device.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then you can define different &amp;quot;states&amp;quot; of operation where a service would operate or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in the code of a service you can have an &amp;quot;if&amp;quot; to check the state, if the state is &amp;quot;A&amp;quot; for example then you will return the correct value in a read call back, or do notification etc. If the state is &amp;quot;B&amp;quot; then you will not return correct value and only return 0. And you don&amp;#39;t do any notification, don&amp;#39;t react to a write command etc.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On the opposite, with another service, the behavior can be different, you react correctly if the state is &amp;quot;B&amp;quot;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;You can use event module to notify to the service about different state changes.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/372863?ContentTypeID=1</link><pubDate>Thu, 16 Jun 2022 14:53:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:596f1229-b782-4b0b-82c0-0ecb90910f14</guid><dc:creator>Deep Patel</dc:creator><description>&lt;p&gt;Hello Hung .&lt;/p&gt;
&lt;p&gt;What do you mean by your statement :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;Meaning if the service is not needed for the operation you simply keep it there and remove any function on the service&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please explain in detail.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I dont mind having a static ATT table (with two or more service definitions .. example Service A, Service B, etc)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Just want to know how to keep things in code, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;such that if USER A Mobile Client.. when connected for Service A, if by accidentally it tries to access (read / write) Service B, what to do ?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/371882?ContentTypeID=1</link><pubDate>Fri, 10 Jun 2022 12:14:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30f85303-7045-4c00-b558-bffdc1e01189</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I would suggest to also look at this library:&amp;nbsp;\zephyr\subsys\bluetooth\mesh\pb_gatt_srv.c&lt;/p&gt;
&lt;p&gt;In the library we use&amp;nbsp;CONFIG_BT_GATT_DYNAMIC_DB and use&amp;nbsp;bt_gatt_service_register() and&amp;nbsp;bt_gatt_service_unregister() to update the ATT table.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;But as I mentioned, this will cause more complex situation when the phone may confuse with the current ATT table if it&amp;#39;s not properly handled. So to make it more simple and robust I would suggest to keep the ATT table static.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/371720?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2022 15:58:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8676a91a-96d9-41ba-ae4f-98a67b893f37</guid><dc:creator>Deep Patel</dc:creator><description>&lt;p&gt;Hello Hung Bai,&lt;/p&gt;
&lt;p&gt;Probably the end user using the mobile phone application (GATT Client), will only see the service which it is looking for.&lt;/p&gt;
&lt;p&gt;But. for testing purposes i am using nRF Connect&amp;nbsp; Mobile App as a sniffer (scanner), and that sees all services and their characteristics (not related to the advertiser) defined in the GATT Server database, which i don&amp;#39;t want to be exposed. Let me look into your example if that helps me.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?</title><link>https://devzone.nordicsemi.com/thread/371614?ContentTypeID=1</link><pubDate>Thu, 09 Jun 2022 10:44:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3897265f-63c2-4a30-a806-73e6ed8235ac</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Deep Patel,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s actually possible to do so. You can have a look at&amp;nbsp;gatt pool library &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/nrf/libraries/bluetooth_services/gatt_pool.html"&gt;here.&lt;/a&gt;&amp;nbsp;I haven&amp;#39;t used it myself but as far as I can see you can find en example of using it inside&amp;nbsp;\nrf\subsys\bluetooth\services\hids.c&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note that changing the attribute table dynamically requires you to send a service change indication to tell the peer device (the phone) to do a service discovery to update the table.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Normally in many application we use fixed attribute table. Meaning if the service is not needed for the operation you simply keep it there and remove any function on the service. This normally doesn&amp;#39;t affect the end user. In most case you have your own app on the phone that can hide the service that is not needed for certain mode of operation. Most of the time the end user wouldn&amp;#39;t be able to see the service/characteristic in raw.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>