<?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 discover services only ones?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9739/how-to-discover-services-only-ones</link><description>Hello, 
 I&amp;#39;m trying to store the discovered services and characteristics only ones at first connection with an bonded device at the central. So following connection events will be faster. Currently my code for the discovery looks like this: 
 case DM_EVT_CONNECTION</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 Jan 2016 08:12:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9739/how-to-discover-services-only-ones" /><item><title>RE: How to discover services only ones?</title><link>https://devzone.nordicsemi.com/thread/36085?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 08:12:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cca3606d-ad84-4a0e-b236-ee3225c8d3e8</guid><dc:creator>michaeld</dc:creator><description>&lt;p&gt;Hi Petter,&lt;/p&gt;
&lt;p&gt;The circumstances have changed it now does matter that the discovery is saved persistently. I want the module to sleep when not used and recover the connection as fast as possible when a button is pressed. Can you give me tips or an example on how to do that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover services only ones?</title><link>https://devzone.nordicsemi.com/thread/36084?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2015 08:49:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:959a4343-9ac3-438f-9367-a86ab7d664b7</guid><dc:creator>michaeld</dc:creator><description>&lt;p&gt;It works well thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover services only ones?</title><link>https://devzone.nordicsemi.com/thread/36083?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2015 12:42:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4804a157-5daa-41b3-9eee-92b1fea901a7</guid><dc:creator>michaeld</dc:creator><description>&lt;p&gt;Many thanks I&amp;#39;m going to try it. Will report back in a few days.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover services only ones?</title><link>https://devzone.nordicsemi.com/thread/36082?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2015 12:01:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:75322d14-f0d1-4642-abcd-0d6da06274b8</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;I mentioned here:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In ble_app_hrs_c the Database
Discovery module does service
discovery to find the attribute
handles for the CCCD and the
characterisitic value for hrs and bas.
To skip this step you need to store
these (persistently or not) on the
first connection and then give them to
ble_hrs_c and ble_bas_c on subsequent
connections.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you don&amp;#39;t need to store them persistenly, you actually don&amp;#39;t need to give the handles to ble_hrs_c and ble_bas_c on subsequent connections, because the handles will be in memory.&lt;/p&gt;
&lt;p&gt;The current flow in ble_app_hrs_c is like this.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Application receives the DM_EVT_CONNECTION event through the device_manager_event_handler and calls ble_db_discovery_start().&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The database discovery module will send events to hrs and bas through db_discover_evt_handler(). If the heart rate service is found hrs will send the BLE_HRS_C_EVT_DISCOVERY_COMPLETE event to main where dm_security_setup_req() and ble_hrs_c_hrm_notif_enable() will be called, triggering bonding and enabling notifications respectively. If the battery service is found bas will send the BLE_BAS_C_EVT_DISCOVERY_COMPLETE event to main where ble_bas_c_bl_notif_enable() will be called.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;(3. When security setup is complete the DM_EVT_SECURITY_SETUP_COMPLETE event is received, which for some unknown reason calls ble_hrs_c_hrm_notif_enable() again.)&lt;/p&gt;
&lt;p&gt;There are probably many ways to solve this, but here is my suggestion.&lt;/p&gt;
&lt;p&gt;Add a flag which is set to true. This is checked in the DM_EVT_CONNECTION event. So service discovery will only be done if it is true. If it is false, dm_security_setup_req() will be called. The flag is set to false on the DM_EVT_SECURITY_SETUP_COMPLETE event.&lt;/p&gt;
&lt;p&gt;Now service discovery is only performed on first connection.&lt;/p&gt;
&lt;p&gt;We also need to make sure that notifications are enabled (CCCD = 0x0001) on the peripheral, so that it is able to send notifications. When you bond with the ble_app_hrs example it should actually store the CCCDs values, and restore them on reconnection. I tested this, and it worked fine the the heart rate service, but the battery service wouldn&amp;#39;t send notifications. I&amp;#39;m not sure why, but I&amp;#39;ll try to look into this some more when I have time.&lt;/p&gt;
&lt;p&gt;I wanted to call ble_hrs_c_hrm_notif_enable() and ble_bas_c_bl_notif_enable() when the DM_EVT_SECURITY_SETUP_COMPLETE event is received, since this will only be received once; when bonding procedure is complete. But as I mentioned then the battery service wouldn&amp;#39;t send notifications this way.&lt;/p&gt;
&lt;p&gt;So instead I call them when the DM_EVT_LINK_SECURED event is received, which will be received on every reconnection (and the first connection). This approach results in two &amp;quot;unnecessary&amp;quot; write requests on reconnection, but this is what I have for now.&lt;/p&gt;
&lt;p&gt;I also commented out some function calls from hrs_c_evt_handler() and bas_c_evt_handler().&lt;/p&gt;
&lt;p&gt;Initial tests shows that it is working, but it is given as is.&lt;/p&gt;
&lt;p&gt;I have attached my project, I added pemy as a codeword all the places (I think) I have made changes.&lt;/p&gt;
&lt;p&gt;Peripheral side: \examples\ble_peripheral\ble_app_hrs, SDK 9.0.0, S110 8.0.0.&lt;/p&gt;
&lt;p&gt;Central side &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_hrs_5F00_c_5F00_cache.rar"&gt;ble_app_hrs_c_cache&lt;/a&gt;, SDK 9.0.0, S120 2.1.0. Should be placed in \examples\ble_central&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_hrs_5F00_c_5F00_cache.pcapng"&gt;Here&lt;/a&gt; is a sniffer trace. You can see on second connection the link gets encrypted, no service discovery, two write requests, and notifications are sent.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover services only ones?</title><link>https://devzone.nordicsemi.com/thread/36081?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2015 16:11:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a7900a2-51c3-4636-8f12-6fca5e0924b2</guid><dc:creator>michaeld</dc:creator><description>&lt;p&gt;For me it doesn&amp;#39;t really mater if it is persistently or not it thought it would be most easy to do it persistently because the Device Manager supports that. I want to bond one device at the time and the peripheral is an simple S110 device with a button. The Central is constantly scanning for it&amp;#39;s bonded device and tries to connect with it.&lt;/p&gt;
&lt;p&gt;This is all working fine but to make the connection extra fast I want to save the discovered services. I tried to implement an none persistent version but I couldn&amp;#39;t really figure out how to do that.&lt;/p&gt;
&lt;p&gt;Now there are these functions meant for saving the context but there is no example anywhere on how to use them. Especially how do I set the p_context pointer or what should I give to this p_context so it knows the discovered services.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to discover services only ones?</title><link>https://devzone.nordicsemi.com/thread/36080?ContentTypeID=1</link><pubDate>Fri, 16 Oct 2015 15:39:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a578d19-b02c-4b40-af51-2df6b1ab6e82</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;I see that you have seen &lt;a href="https://devzone.nordicsemi.com/question/43446/s120-central-bonding-with-s110-peripheral/"&gt;this&lt;/a&gt; And that you have asked about michiel&amp;#39;s implementation. As he said he didn&amp;#39;t implement this persistently or with the device manager. But here you ask about and implementation that is persistent and with the device manager. Could you explain a bit more about your application? What kind of peripherals are you connecting to? How many?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>