<?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 set BLE device name based on device parameters</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74587/how-to-set-ble-device-name-based-on-device-parameters</link><description>Dear Nordic, 
 we would like to set the BLE device name like this: &amp;quot;model&amp;quot; &amp;quot;serial number&amp;quot; (for example: &amp;quot;Model 024585&amp;quot;). 
 The serial number is on a EEPROM, and the device name will have the same nave from the startup to the poweroff. 
 Following your</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 19 Oct 2023 17:50:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74587/how-to-set-ble-device-name-based-on-device-parameters" /><item><title>RE: How to set BLE device name based on device parameters</title><link>https://devzone.nordicsemi.com/thread/451375?ContentTypeID=1</link><pubDate>Thu, 19 Oct 2023 17:50:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6c4f7bb-14fc-45ae-8dfd-09acd6b73966</guid><dc:creator>Randy Lee</dc:creator><description>&lt;p&gt;I&amp;#39;m using SDK 15.3 on a 52840 and this works on startup, no problem.&lt;/p&gt;
&lt;p&gt;Now suppose I want to change the name every couple of minutes?&amp;nbsp; I can set the name with this code but it&amp;#39;s not changing on the adverts as far as I can see.&amp;nbsp; Must be missing something.&lt;/p&gt;
&lt;p&gt;This post (&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/9963/how-to-change-the-device-name"&gt;How to change the device name?&lt;/a&gt;) says to issue a function call that doesn&amp;#39;t exist in this version of SDK (the post is quite old) and I haven&amp;#39;t figured out what the right one is in this version of SDK.&amp;nbsp; If I go back for an init using ble_advertising_init(), I get an 8 error code back.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to set BLE device name based on device parameters</title><link>https://devzone.nordicsemi.com/thread/307612?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 08:43:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6cae287-7d16-4849-b02a-8aeb35731164</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I left the typecast there because we use it in our examples, but it&amp;#39;s not required.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to set BLE device name based on device parameters</title><link>https://devzone.nordicsemi.com/thread/307470?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 12:05:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b646dc39-cac7-4681-801e-4fd4e26704fb</guid><dc:creator>StefXinet</dc:creator><description>&lt;p&gt;Thanks Vidar,&lt;/p&gt;
&lt;p&gt;your solution is clear, but in this case you are passing to&amp;nbsp;sd_ble_gap_device_name_set() a uint8_t* that isn&amp;#39;t &lt;strong&gt;const&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ok for the typecasting, but could sd_ble_gap_device_name_set() accept a NON const pointer to string?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to set BLE device name based on device parameters</title><link>https://devzone.nordicsemi.com/thread/307444?ContentTypeID=1</link><pubDate>Thu, 29 Apr 2021 11:20:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3c40353-2695-48c0-9732-5cecfc726706</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You need to prepare the string into a contiguous buffer before you pass it to sd_ble_gap_device_name_set(). It may look something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void gap_params_init(void)
{
    uint32_t err_code;
    char device_name_str[BLE_GAP_DEVNAME_DEFAULT_LEN];
    char name[] = &amp;quot;Model&amp;quot;;
    char sn[]   = &amp;quot;024585&amp;quot;; // Serial number to be loaded from an ext. EEPROM  
    
    sprintf(device_name_str, &amp;quot;%s %s&amp;quot;, name, sn);

    err_code = sd_ble_gap_device_name_set(&amp;amp;sec_mode,
                                          (const uint8_t *) device_name_str,
                                          strlen(device_name_str));
    APP_ERROR_CHECK(err_code);
        
    ...    &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps. If anything is unclear, let me know.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>