<?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>nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83749/nrf52-dk-as-central-to-discover-services-on-peripheral</link><description>Hello Nordic team! 
 
 I&amp;#39;m working on a BLE app with the nRF52-DK and an armband(M6) that has a heart rate sensor. My goal is to discover this service and read those values from the nRF52 as a central. 
 So far I&amp;#39;m able to connect to the armband, and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 Jan 2022 14:41:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83749/nrf52-dk-as-central-to-discover-services-on-peripheral" /><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348979?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 14:41:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d2ae278-da5d-4e99-9812-aebe6562febe</guid><dc:creator>Juan Gomez</dc:creator><description>&lt;p&gt;Hello Hung,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I did something easier, just bought a more expensive and original armband and it is indeed advertising the heart rate service in a standard fashion :)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks a lot for your help, it helped me to understand how discovery service works.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hope you have a great day&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348865?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 09:22:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18e87ce6-188f-4d99-9a1d-48b385570940</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Juan,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I would suggest you to get very familiar with the ble_app_uart and the ble_app_uart_c to understand how the system work first before you start to test with the armband and develop your own central device.&amp;nbsp;&lt;br /&gt;You need to understand the difference between the UUID included in the advertising packet and the UUID in the attribute table.&amp;nbsp;&lt;br /&gt;What included in the advertising packet doesn&amp;#39;t need to reflect everything in the attribute table. It&amp;#39;s just a way to tell the central device some information about the peripheral. A heart rate sensor can advertise with just the name and no&amp;nbsp;UUID, it&amp;#39;s fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You also need to get&amp;nbsp;familiar with how to define the UUID base and how the 2 bytes 13 and 14 of the service UUID and characteristic UUID is fit in the base. Please pay attention to the endianess.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;What I would suggest you to do is to start from ble_app_uart, ble_app_uart_c , verify that it works. After that you modify them to use the same UUID as the armband using. Try to mimic that UUID and verify that the central can discover the peripheral. After that you can start to test with the armband.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348802?ContentTypeID=1</link><pubDate>Thu, 20 Jan 2022 19:02:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06c323d3-dece-4a81-b60c-3f8a678023c4</guid><dc:creator>Juan Gomez</dc:creator><description>&lt;p&gt;Hello Hung, thanks a lot!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The error was that the ble_app_uart_c example doesn&amp;#39;t have&amp;nbsp;NRF_BLE_SCAN_NAME_CNT and&amp;nbsp;NRF_BLE_SCAN_ADDRESS_CNT as 1 on the sdk_config.h, so, when&amp;nbsp;nrf_ble_scan_filter_set() was called, it never found those definitions.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I changed the definitions to 1, and the application is able to find my service and my characteristics, thanks a lot :)&lt;/p&gt;
&lt;p&gt;Now I&amp;#39;m trying to print the data for that characteristic. I&amp;#39;m using the struct p_evt in static void db_disc_handler(ble_db_discovery_evt_t * p_evt) to print all the info about the discovery, but I&amp;#39;m not able to find the data value inside it.&lt;/p&gt;
&lt;p&gt;I really appreciate it if you can guide me on that part. Since the nus, hrs, and bas have their own event handler and different switches for their events, I&amp;#39;m not sure how to implement one for mine, like for example, the event handler to read the data.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks in advance and have a great day :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Edit: Checking the nRF connect app I realized that the custom service I was trying to discover was not the heart rate service, but a&amp;nbsp;blood pressure service. And, it doesn&amp;#39;t advertise both up and down values like 120/90, but only the 90 value(in the smart band display both values are printed).&lt;/p&gt;
&lt;p&gt;As far as I know, BLE doesn&amp;#39;t mandate to advertise all services, so, maybe it is possible that the M6 Smart Band I&amp;#39;m using doesn&amp;#39;t advertise the heart rate service? and maybe that&amp;#39;s the reason why ble_app_hrs_c doesn&amp;#39;t find it?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If that&amp;#39;s so, it is possible to discover ALL the services in the peripheral? even if they are not shown in the nRF connect app?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks again&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348708?ContentTypeID=1</link><pubDate>Thu, 20 Jan 2022 13:02:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2535eda7-613c-4b69-b5f4-37ee45568d71</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Juan,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp;The&amp;nbsp;&lt;span&gt;ble_app_hrs_c use heart rate UUID as the filter so it&amp;#39;s normal that it doesn&amp;#39;t connect to your device if your device doesn&amp;#39;t have the UUID of the heart rate&amp;nbsp;service. But in that example we also have filter by name or by address, please look for this code:&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if (strlen(m_target_periph_name) != 0)
    {
        err_code = nrf_ble_scan_filter_set(&amp;amp;m_scan,
                                           SCAN_NAME_FILTER,
                                           m_target_periph_name);
        APP_ERROR_CHECK(err_code);
    }

    if (is_connect_per_addr)
    {
       err_code = nrf_ble_scan_filter_set(&amp;amp;m_scan,
                                          SCAN_ADDR_FILTER,
                                          m_target_periph_addr.addr);
       APP_ERROR_CHECK(err_code);
    }
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can implement something similar in your code.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;When you see an error, you need to figure out which error code it is. You can do that by adding DEBUG into the preprocessor symbols in the&amp;nbsp;solution setting in SES. You can either see that in the log or add a breakpoint that the function failed and check the error code.&amp;nbsp;&lt;br /&gt;Please pay attention to what Olaf asked in the other case, there could be a chance that the name was too long.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348592?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 20:36:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76585e8c-4357-4529-ad35-8b6c47343394</guid><dc:creator>Juan Gomez</dc:creator><description>&lt;p&gt;Hello Hung, thanks a lot for your answer, it really helped me a lot!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tested the&amp;nbsp;&lt;span&gt;ble_app_hrs_c&amp;nbsp;and indeed it doesn&amp;#39;t find my custom Heart Rate Service because it is being advertised with a custom 128 UUID.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I understood how to add the custom 128 UUID using the&amp;nbsp;sd_ble_uuid_vs_add() and I implemented it in the&amp;nbsp;&amp;nbsp;ble_app_uart_c, but it is not connecting to my device, so&amp;nbsp;ble_db_discovery_start() never happens.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I believe this is a scan problem&lt;/span&gt;&lt;span&gt;, so I used the scan functions that worked for me in the past:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static char const m_target_periph_name[] = &amp;quot;M6&amp;quot;;  

//inside scan_init

err_code = nrf_ble_scan_filters_enable(&amp;amp;m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
APP_ERROR_CHECK(err_code);

err_code = nrf_ble_scan_filter_set(&amp;amp;m_scan, SCAN_NAME_FILTER, m_target_periph_name);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, this is generating an&amp;nbsp;&amp;lt;error&amp;gt; app: Fatal error :(&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So:&lt;/p&gt;
&lt;p&gt;1. if I add my custom 128 UUID which I&amp;#39;m pretty sure I did it correctly, it doesn&amp;#39;t connect to any device, discovery never happens&lt;/p&gt;
&lt;p&gt;2. if I change the filters_enable and filter_set functions to look for the device name, it generates an error&lt;/p&gt;
&lt;p&gt;The actual functions causing the error seem to be&amp;nbsp;&lt;span&gt;nrf_ble_scan_filter_set(), but if I comment it, it won&amp;#39;t find my peripheral name.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How should I proceed from here? or what should I be looking at?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks a lot in advance&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348367?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 16:59:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b3491b6-0bbe-415e-92ba-76bcb1c756cb</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi again,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please follow the documentation of the database discovery module &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_ble_db_discovery.html?cp=8_1_3_2_3"&gt;here.&lt;/a&gt;&amp;nbsp;Please attention to the message sequence chart and try to look for the function described in the ble_app_hrs_c&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- The HRM service in ble_app_hrs and ble_app_hrs_c is not&amp;nbsp;custom service, it&amp;#39;s almost the same as the battery service. Unless you are modifying the heart rate service to create your own ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- If you are doing custom service, you should study&amp;nbsp;ble_nus_c_init(), in that you can see the uuid base is added to the database using&amp;nbsp;sd_ble_uuid_vs_add(). The output of this function is&amp;nbsp;&amp;nbsp;&amp;amp;p_ble_nus_c-&amp;gt;uuid_type. This is the index of the base UUID in the database. You then use this &amp;quot;uuid_type&amp;quot; (the index) as the input to the&amp;nbsp;uart_uuid.type and then add the 2 bytes (which will be bytes 13th and 14th on top of the base UUID) into&amp;nbsp;&amp;nbsp; &amp;nbsp; uart_uuid.uuid&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1642524860366v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Then you register the uuid with&amp;nbsp;ble_db_discovery_evt_register().&amp;nbsp;&lt;br /&gt;&lt;br /&gt;When the service discovery is completed,&amp;nbsp;ble_nus_c_on_db_disc_evt() will be called and from there you check if the service you are looking for is found or not. If not you can ignore it and there may be another&amp;nbsp;BLE_DB_DISCOVERY_COMPLETE event will come.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348318?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 14:22:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4efd453a-d57e-4490-ad2b-cb0be63ae72e</guid><dc:creator>Juan Gomez</dc:creator><description>&lt;p&gt;Hi Hung, thanks a lot for your quick response!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I used the ble_app_hrs_c and I was able to find the battery service from my peripheral because it is advertising it with a standard UUID. But, since the heart rate service is a custom UUID, the example doesn&amp;#39;t work out of the box. I tried this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define PERIPHERAL_SERVICE_BASE_UUID { 0x6E, 0x40, 0x00, 0x03, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9f } 

#define TARGET_UUID                   PERIPHERAL_SERVICE_BASE_UUID

//inside scan_init()
    ble_uuid_t uuid =
    {
        .uuid = TARGET_UUID,
        .type = BLE_UUID_TYPE_VENDOR_BEGIN,
    };&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand which variable do I need to check in order to know if the discovery handler found this UUID, nor where do I have to write that code. Is there a function for a custom uuid discovery event that I should add to db_disc_hanlder()?&lt;/p&gt;
&lt;p&gt;I also worked on the ble_app_uart_c but this one is more complicated for me, since it is not connecting :(&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define PERIPHERAL_SERVICE_BASE_UUID { 0x6E, 0x40, 0x00, 0x03, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9f } 
#define PERIPHERAL_SERVICE_CHAR_UUID {0x0003}

// changed the nus_uuid in the example
static ble_uuid_t const m_nus_uuid =
{
    .uuid = PERIPHERAL_SERVICE_BASE_UUID,
    .type = BLE_UUID_TYPE_VENDOR_BEGIN
};

//inside ble_nus_c_on_db_disc_evt not sure what do I need to change here
    // Check if the NUS was discovered.
    if (    (p_evt-&amp;gt;evt_type == BLE_DB_DISCOVERY_COMPLETE)
        &amp;amp;&amp;amp;  (p_evt-&amp;gt;params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE)
        &amp;amp;&amp;amp;  (p_evt-&amp;gt;params.discovered_db.srv_uuid.type == p_ble_nus_c-&amp;gt;uuid_type))&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Since neither worked for me, I created a simple example to scan and do a discovery service. The scan part is working great and I&amp;#39;m connecting to my peripheral, so the question is: If I would like to add simple discovery code how would I proceed?&lt;/p&gt;
&lt;p&gt;I followed the Bluetooth low energy central tutorial from Nordic but I get lost on points 3 and 4&lt;/p&gt;
&lt;p&gt;1.&amp;nbsp;&lt;span&gt;BLE_DB_DISCOVERY_DEF(m_db_disc);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;2.&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;ble_db_discovery_init()&lt;/code&gt;&lt;span&gt;&amp;nbsp;in&amp;nbsp;&lt;/span&gt;&lt;code&gt;main()&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;3.&amp;nbsp;&lt;span&gt;callback function to handle events and forward the event to their respective service&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;4.&amp;nbsp;Register a service UUID which the db_discovery module shall look&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;5.Start a service discovery using ble_db_discovery_start()&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In point 3 the example uses the NUS, but since I&amp;#39;m looking for a custom service, this part is really confusing for me. In point 4,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:inherit;"&gt;this is done with sd_ble_uuid_vs_add()? if so, where should I add this code?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Thanks again in advance Hung!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52-DK as CENTRAL to discover services on peripheral</title><link>https://devzone.nordicsemi.com/thread/348239?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 10:37:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:acd38f3f-7b46-437f-a91e-441e319c0d19</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Juan,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you have any trouble testing the ble_app_hrs and the ble_app_hrs_c ?&amp;nbsp;&lt;br /&gt;The ble_app_hrs_c is&amp;nbsp;expected&amp;nbsp;to read the ble_app_hrs&amp;#39; heart rate value out of the box.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;We already provided the service discovery module (ble_db_discovery) so you don&amp;#39;t have to do that in the code. Please follow what we did in the example. You can have a look at the ble_app_uart_c. It&amp;#39;s an example of how you can do service discovery for proprietary service. Notice how&amp;nbsp;ble_db_discovery_evt_register() is called inside ble_nus_c.c and how discovery is started &amp;nbsp;BLE_GAP_EVT_CONNECTED event in main.c (call ble_db_discovery_start() )&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>