<?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 to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example</link><description>Hello, I read the instructions here for using the Nordic NRF Connect app for testing the CTS example: https://devzone.nordicsemi.com/f/nordic-q-a/53382/implementing-current-time-service-example 
 However, I do not see an option in the app for configuring</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 31 Aug 2020 18:53:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example" /><item><title>RE: How to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/thread/267313?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 18:53:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b15de298-37b3-419f-a4c9-bf09a8bc582e</guid><dc:creator>nordev</dc:creator><description>&lt;p&gt;Thank you again for your extremely helpful and detailed replies. I have one last question:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;what does the &amp;quot;c&amp;quot; stand for in ble_cts_c? Is it &amp;quot;client&amp;quot;? I see this in various places in the nordic code and am not sure what the notation means... what is the purpose of this notation?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/thread/266991?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 11:57:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efff9c24-fc73-4f19-aada-43a1749381b9</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="nordev"]Hypothetically, if I develop a custom service for the central, should I put something equivalent to custom_service_on_db_disc_evt() into the db_disc_handler() as well, just like how it is for CTS?[/quote]
&lt;p&gt;Yes, if you make a custom service client, then you need to be able to discover it. And it makes sense to use the same approach as in the SDK examples.&lt;/p&gt;
[quote user="nordev"]ble_cts_c_on_ble_evt() seems like a callback function too, but it doesn&amp;#39;t seem to be registered anywhere.[/quote]
&lt;p&gt;It is a bit difficult to see, but you should look at the definition of&amp;nbsp;BLE_CTS_C_DEF in ble_cts_c.h. This includes&amp;nbsp;NRF_SDH_BLE_OBSERVER which adds&amp;nbsp;ble_cts_c_on_ble_evt to the list of BLE observers. This is a section variable holding function pointers that should get all BLE events, so this makes the SoftDevice handler call&amp;nbsp;ble_cts_c_on_ble_evt. Section variables are a bit like black magic, but it works&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&amp;nbsp;.&lt;/p&gt;
[quote user="nordev"]What passes it the events?&amp;nbsp;[/quote]
&lt;p&gt;If you want to look into the details you can check nrf_sdh.c, which is where the handler is called from. If you have configured to use the scheduler for BLE events, this is done by&amp;nbsp;nrf_sdh_evts_poll().&lt;/p&gt;
[quote user="nordev"]To clarify, the applications event handler is on_cts_c_evt(), and ble_cts_c_on_ble_evt() is the SoftDevice event handler?[/quote]
&lt;p&gt;Yes, sort off.&amp;nbsp;on_cts_c_evt() is the applications event handler that handles events from the&amp;nbsp;CTS client (ble_cts_c), and&amp;nbsp;ble_cts_c_on_ble_evt() is the CTS client module&amp;#39;s event handler for handling events form the SoftDevice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/thread/266851?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 04:15:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e6522a4-5f80-4a44-bd66-5ae9071c6b05</guid><dc:creator>nordev</dc:creator><description>[quote userid="7377" url="~/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example/266411"]Events from the discovery module is passed to the CTS implementation by the call to&amp;nbsp;ble_cts_c_on_db_disc_evt() within&amp;nbsp;db_disc_handler()[/quote]
&lt;p&gt;Hypothetically, if I develop a custom service for the central, should I put something equivalent to custom_service_on_db_disc_evt() into the db_disc_handler() as well, just like how it is for CTS?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1598581743278v1.png" alt=" " /&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example/266715"]you will see the&amp;nbsp;ble_cts_c_on_ble_evt() handler which handled events, and it calls&amp;nbsp;current_time_read() do process this before it calls the applications event handler in the end. That is where you see this in your application. In the example, the event handler is&amp;nbsp;on_cts_c_evt() in the main., and that is where you read it.[/quote]
&lt;p&gt;ble_cts_c_on_ble_evt() seems like a callback function too, but it doesn&amp;#39;t seem to be registered anywhere. What passes it the events?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To clarify, the applications event handler is on_cts_c_evt(), and ble_cts_c_on_ble_evt() is the SoftDevice event handler?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you again for the helpful and detailed answers!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/thread/266715?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 11:37:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5c69f9f-ab4a-436b-ab9e-972e6beeacd4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="nordev"]Do you mean that these have to be added on the phone side in the NRF app, or on the firmware side? If the former, how do you add a service and characteristic in the app -- I did not see an option to do so...[/quote]
&lt;p&gt;You are right, I was writing too fast. That is only available on the Android version. So you have to use nRF Connect for desktop or nRF Connect for Android to do this test.&lt;/p&gt;
[quote user="nordev"]Do you mean that the CTS instance and anything else registered as an observer each gets ALL the BLE events that occur and has to filter internally which events are relevant / can be handled by itself?[/quote]
&lt;p&gt;Yes, that is how it is done.&lt;/p&gt;
[quote user="nordev"]Does it handle all BLE events, or only events associated with services?[/quote]
&lt;p&gt;The service implementation only handles what it cares about and ignore other events.&lt;/p&gt;
[quote user="nordev"]If my previous statement is true, does that mean ble_cts_c_current_time_read() passes an event to the db discovery module?[/quote]
&lt;p&gt;No. The discovery module is used for service discovery, and no longer used when that is done.&amp;nbsp;ble_cts_c_current_time_read() is implemented in the CTS client implementation (components\ble\ble_services\ble_cts_c\ble_cts_c.c), and that just makes a GATTC read operation. That is queued and handled by the SoftDevice, which will generate an event when the read is completed. If you look more in ble_cts_c.c, you will see the&amp;nbsp;ble_cts_c_on_ble_evt() handler which handled events, and it calls&amp;nbsp;current_time_read() do process this before it calls the applications event handler in the end. That is where you see this in your application. In the example, the event handler is&amp;nbsp;on_cts_c_evt() in the main., and that is where you read it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/thread/266689?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2020 10:08:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17e6020f-33a7-40ba-bb30-6f10abee706c</guid><dc:creator>nordev</dc:creator><description>&lt;p&gt;Thank you so much for this thorough reply!&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example/266411"]You can set this up for iOS also, but then you need to configure it manually by adding the CTS service (UUID 0x1805) and the current time characteristic (UUID 0x2A2B)[/quote]
&lt;p&gt;Do you mean that these have to be added on the phone side in the NRF app, or on the firmware side? If the former, how do you add a service and characteristic in the app -- I did not see an option to do so...&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example/266411"]The CTS implementation gets all BLE events as it is registered as an observer by the&amp;nbsp;NRF_SDH_BLE_OBSERVERS macro which is part of the&amp;nbsp;BLE_CTS_C_DEF macro.[/quote]
&lt;p&gt;Do you mean that the CTS instance and anything else registered as an observer each gets ALL the BLE events that occur and has to filter internally which events are relevant / can be handled by itself? Or if not, do you mean that the db_discovery handles&amp;nbsp;the filtering of events to the right modules? Does it handle all BLE events, or only events associated with services?&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/65209/how-to-configure-gatt-server-in-nrf-app-to-test-cts-example/266411"]Once the service is discovered, you can get the current time by calling&amp;nbsp;ble_cts_c_current_time_read().[/quote]
&lt;p&gt;If my previous statement is true, does that mean ble_cts_c_current_time_read() passes an event to the db discovery module?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure GATT server in NRF app to test CTS example</title><link>https://devzone.nordicsemi.com/thread/266411?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 09:15:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22361f9f-2704-4f45-88f9-8c596553d3d5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]Question 1: How do I configure the GATT server on the NRF app to make my phone a Current Time server?[/quote]
&lt;p&gt;The instructions in the example documentation are for nRF Connect for Desktop. Using that you simply import the&amp;nbsp;cts_central.ncs by selecting Server Setup and loading the file:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-a6418384e48b447882e3a10baea00249/server_5F00_setup.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;You can set this up for iOS also, but then you need to configure it manually by adding the CTS service (UUID 0x1805) and the current time characteristic (UUID 0x2A2B).&lt;/p&gt;
[quote user=""]Question 2: How does the current time service get called?[/quote]
&lt;p&gt;You can see this from the example in the SDK (examples\ble_peripheral\ble_app_cts_c\main.c), and this follows the same approach as all other services in the SDK.&lt;/p&gt;
[quote user=""]In the second screenshot (see references in left sidebar), it is evident that the event handler is never&amp;nbsp;&lt;strong&gt;&lt;/strong&gt;explicitly called. So how is an event generated?[/quote]
&lt;p&gt;The&amp;nbsp;on_cts_c_evt() function is a callback function / event handler that is registered when you initialize the CTS service (see the services_init() function in the example). The CTS implementation gets all BLE events as it is registered as an observer by the&amp;nbsp;NRF_SDH_BLE_OBSERVERS macro which is part of the&amp;nbsp;BLE_CTS_C_DEF macro. So when there is a BLE event that is handled by the service implementation (components\ble\ble_services\ble_cts_c\ble_cts_c.c), which calls the registered event handler when appropriate.&lt;/p&gt;
[quote user=""]What does the client (NRF device) have to do to discover the Current Time Server[/quote]
&lt;p&gt;That is part of the service discovery procedure which is handled by the DB discovery module. Looking at main.c again, you can see in pm_evt_handler() that service discovery is started once the link is encrypted, by the call to&amp;nbsp;ble_db_discovery_start(). Events from the discovery module is passed to the CTS implementation by the call to&amp;nbsp;ble_cts_c_on_db_disc_evt() within&amp;nbsp;db_disc_handler(). And here the CTS module does as described before, handles the event, and if relevant, passes an event back to the registered event handler (BLE_CTS_C_EVT_DISCOVERY_COMPLETE or&amp;nbsp;BLE_CTS_C_EVT_DISCOVERY_FAILED in this case).&lt;/p&gt;
[quote user=""]or to request a Current Time reading from the server?[/quote]
&lt;p&gt;Once the service is discovered, you can get the current time by calling&amp;nbsp;ble_cts_c_current_time_read(). Then wait for the&amp;nbsp;BLE_CTS_C_EVT_CURRENT_TIME event and do something with it (the example prints it using&amp;nbsp;current_time_print()).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>