<?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>Central device, match filter for a substring of the name</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/45607/central-device-match-filter-for-a-substring-of-the-name</link><description>Hi, 
 I am trying to develop a central device that would scan for devices that start with a prefix XYZ_, for example XYZ_1111, XYZ_1245,... 
 Is there some way to add a name scan filter for the central device in SDK 15.3 that would trigger an event match</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Apr 2019 07:18:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/45607/central-device-match-filter-for-a-substring-of-the-name" /><item><title>RE: Central device, match filter for a substring of the name</title><link>https://devzone.nordicsemi.com/thread/179665?ContentTypeID=1</link><pubDate>Tue, 02 Apr 2019 07:18:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcd2d569-cb0b-48e1-a453-7cb393bcb00f</guid><dc:creator>KlevioRok</dc:creator><description>&lt;p&gt;Thank you Simon! This helps a lot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central device, match filter for a substring of the name</title><link>https://devzone.nordicsemi.com/thread/179521?ContentTypeID=1</link><pubDate>Mon, 01 Apr 2019 13:22:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bfa4f63-218a-4b64-a9f6-563547f0c607</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I would recommend you to take a look at the &lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/ble_sdk_app_hrc"&gt;BLE Heart Rate Collector Example&lt;/a&gt;&lt;span&gt;&amp;nbsp;located in &lt;em&gt;&amp;lt;InstallFolder&amp;gt;\examples\ble_central\ble_app_hrs_c. &lt;/em&gt;It demonstrates how to perform scan filtering based on advertising name by using the&amp;nbsp;nrf_ble_scan Scanning Module.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The scan library checks the advertising name in the following manner: &lt;em&gt;nrf_ble_scan_on_ble_evt()--&amp;gt; nrf_ble_scan_on_adv_report()--&amp;gt;adv_name_compare()--&amp;gt;ble_advdata_name_find().&amp;nbsp;&lt;/em&gt;However, it will only return true if the name in the filter matches name in the advertising packet by length and content.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In order to compare only the x first characters you will have to modify the ble_advdata_name_find() in the following manner:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Swap these lines:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (   (data_offset != 0)
    &amp;amp;&amp;amp; (parsed_name_len != 0)
    &amp;amp;&amp;amp; (strlen(p_target_name) == parsed_name_len)
    &amp;amp;&amp;amp; (memcmp(p_target_name, p_parsed_name, parsed_name_len) == 0))&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;With these:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (   (data_offset != 0)
    &amp;amp;&amp;amp; (parsed_name_len != 0)
    &amp;amp;&amp;amp; (parsed_name_len &amp;gt;= strlen(p_target_name))
    &amp;amp;&amp;amp; (memcmp(p_target_name, p_parsed_name, strlen(p_target_name)) == 0))&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have not tested it, but I think it should work. However, this modification will change the library (&lt;em&gt;ble_advdata.c&lt;/em&gt;), and might mess up other projects using that library. In order to avoid this you can make a copy of the library or create your own modified function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>