<?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>I want to get pheriphetial device name..</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81591/i-want-to-get-pheriphetial-device-name</link><description>I am a beginner developer. 
 I am working on ble_app_multilink_central and ble_app_uart-based projects and succeeded in BLE multi-connecting. But there is a problem. An error occurs in the BLE connection. In my project, when the device names of central</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Nov 2021 06:20:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81591/i-want-to-get-pheriphetial-device-name" /><item><title>RE: I want to get pheriphetial device name..</title><link>https://devzone.nordicsemi.com/thread/338472?ContentTypeID=1</link><pubDate>Thu, 11 Nov 2021 06:20:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cd67ba5-823c-4c38-bd45-cdffce9029fa</guid><dc:creator>eggmoneyna</dc:creator><description>&lt;p&gt;Thanks for your reply.&lt;br /&gt;I can check the log and I tried it.&lt;/p&gt;
&lt;p&gt;Before that I found a solution.&lt;br /&gt;Through many posts, I found information that the peripheral device name can be obtained by using ble_advdata_parse() or ble_advdata_search() from BLE_GAP_EVT_ADV_REPORT of &amp;#39;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)&amp;#39;.&lt;/p&gt;
&lt;p&gt;However, when I actually debugged, I don&amp;#39;t know why, but the next operation of &amp;#39;ble_advdata_parse()&amp;#39; did not proceed.&lt;/p&gt;
&lt;p&gt;So I got the peripheral name from on_adv_report().&lt;/p&gt;
&lt;p&gt;This is my code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
{
    ret_code_t err_code;
    uint16_t data_offset = 0;
    int parsed_name_len = ble_advdata_search(p_adv_report-&amp;gt;data.p_data, p_adv_report-&amp;gt;data.len, &amp;amp;data_offset, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
    uint8_t *buf = ble_advdata_parse(p_adv_report-&amp;gt;data.p_data, p_adv_report-&amp;gt;data.len, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);

    if ( ble_advdata_name_find(p_adv_report-&amp;gt;data.p_data, parsed_name_len, m_target_periph_name) || ble_advdata_name_find(p_adv_report-&amp;gt;data.p_data, parsed_name_len, DEVICE_NAME))    
    {
        scan_stop();
        // Name is a match, initiate connection.
        err_code = sd_ble_gap_connect(&amp;amp;p_adv_report-&amp;gt;peer_addr,
                                      &amp;amp;m_scan_params,
                                      &amp;amp;m_connection_param,
                                      APP_BLE_CONN_CFG_TAG);
            if (err_code != NRF_SUCCESS)
            {
#ifdef DEBUG 		
                printf(&amp;quot;Connection Request Failed, reason %d \r\n&amp;quot;, err_code);
#endif			
            }
            else
            {
#ifdef DEBUG 		
                printf(&amp;quot;\r\n P name : &amp;quot;);
                for(int i  = 0 ; i &amp;lt; parsed_name_len; i++)
                {
                    printf(&amp;quot;%c&amp;quot;, buf[i]);
                }
                printf(&amp;quot;\r\n&amp;quot;);
                printf(&amp;quot;Connection Request SUCESSED, reason %d \r\n&amp;quot;, err_code);
#endif            
            }

        }
    }
    else
    {

        scan_stop();
        scan_start();

    }
    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The difference from the previous code is &amp;#39;ble_advdata_name_find()&amp;#39;.&lt;br /&gt;[before]&lt;br /&gt;ble_advdata_name_find(p_adv_report-&amp;gt;data.p_data, p_adv_report-&amp;gt;data.len, m_target_periph_name)&lt;/p&gt;
&lt;p&gt;[after]&lt;br /&gt;ble_advdata_name_find(p_adv_report-&amp;gt;data.p_data, parsed_name_len, m_target_periph_name)&lt;/p&gt;
&lt;p&gt;When I printed &amp;#39;p_adv_report-&amp;gt;data.len&amp;#39;, the length of the device name did not match.&lt;br /&gt;Therefore, the length of the device name was obtained using ble_advdata_search() and then debugged.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Now I have to go back to the original purpose and check if the BLE connection is made with a peripheral device with a different name.&lt;br /&gt;I don&amp;#39;t know if it&amp;#39;s a MAC address problem or the ad packet of the peripheral is broken, but I&amp;#39;ll try to solve this problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I want to get pheriphetial device name..</title><link>https://devzone.nordicsemi.com/thread/338369?ContentTypeID=1</link><pubDate>Wed, 10 Nov 2021 12:12:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:477cacdf-9c80-4848-b82a-aea8597ba727</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Maybe do an on-air sniffer log to see actually what is on-air?&lt;br /&gt;&lt;a href="https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE"&gt;https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, you can split the if() statement in two, to check which of the m_target_periph_name vs. DEVICE_NAME is triggering true.&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t really think of anything, though you can check the implementation of&amp;nbsp;ble_advdata_name_find() and&amp;nbsp;ble_advdata_search() with a newer nRF5 SDK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>