<?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>Incomplete data advertised while changing the advertising data during advertising</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34980/incomplete-data-advertised-while-changing-the-advertising-data-during-advertising</link><description>Hi, 
 
 I have been trying to advertise packets with different manufacturer data and I am able to achieve that using the radio_notification_handler of the SDK. In my code, I have initialized the manufacturer data in the ble_advertising_init() function</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 03 Jun 2018 07:08:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34980/incomplete-data-advertised-while-changing-the-advertising-data-during-advertising" /><item><title>RE: Incomplete data advertised while changing the advertising data during advertising</title><link>https://devzone.nordicsemi.com/thread/134430?ContentTypeID=1</link><pubDate>Sun, 03 Jun 2018 07:08:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:172d141f-140d-41ea-88f5-16a58cb64221</guid><dc:creator>Atul Bansal</dc:creator><description>&lt;p&gt;Thank you for your help! It completely solved my problem. I can&amp;#39;t believe I missed such a small bug.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The putter() function is something like this:-&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t * putter(char str[])
{
	int l = strlen(str);
	uint8_t * u = (uint8_t *) malloc(l+1);
	strcpy (u, str);
	return u;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding efficiency, I know it&amp;#39;s inefficient. I was just trying to recreate an example similar to what I am doing so that I can convey my problem easily to the people here. Anyway, thanks for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incomplete data advertised while changing the advertising data during advertising</title><link>https://devzone.nordicsemi.com/thread/134428?ContentTypeID=1</link><pubDate>Sun, 03 Jun 2018 03:32:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26ad957d-f52f-4c29-8382-4ddfcf21c2fc</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;That code is just random. First of all you are setting (in the function) data to be an array of 5 byte pointers (uint8_t*), then you are assigning each of them to the result of putter() with an 8 byte null terminated string. It rather depends on what putter() does/returns what happens but I assume you just end up with the address of the fixed string in data[].&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then you set the manufacturer data pointer to the one&amp;nbsp;pointer in your data array, which possibly contains something pointing to one of the&amp;nbsp;character strings you tried to store with putter(); depending on what putter() actually does.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You then tell it the size of the manufacturer data is sizeof( data[i] ) and the size of a uint8_t * on Cortex M0/4 is 4, so you&amp;#39;ve set the manufacturer data to 4 bytes at whatever data[i] points to. So that&amp;#39;s why you&amp;#39;re getting 4 bytes. Indeed in your first example the data is 0x66676869 which is &amp;quot;fghi&amp;quot; and in the second example it&amp;#39;s 0x61766277 which is &amp;#39;avbw&amp;#39; which are actually the first 4 characters of the first two strings so your code is sort of doing exactly what it says.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The function is wildly inefficient as you set up the whole data[] array, fill it up calling putter() on it and then toss 4/5 of it away each time through the loop; where all you actually wanted to do is put&amp;nbsp;the address of one of your fixed strings in the manufacturer data &amp;nbsp;pointer and set the length to 7.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incomplete data advertised while changing the advertising data during advertising</title><link>https://devzone.nordicsemi.com/thread/134406?ContentTypeID=1</link><pubDate>Fri, 01 Jun 2018 18:08:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2690c597-6975-4290-84eb-0bfa55f364be</guid><dc:creator>Atul Bansal</dc:creator><description>&lt;p&gt;Sure.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is the advertising_init() function:-&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void advertising_init(void)
{
    ret_code_t             err_code;
    ble_advertising_init_t init;

    memset(&amp;amp;init, 0, sizeof(init));

 

    ble_advdata_manuf_data_t manuf_data;
    uint8_t data[]                      = &amp;quot;ABCDEFGHIJ&amp;quot;; // Our data to advertise
    manuf_data.company_identifier       = 0xFFFF; // Unregistered company
    manuf_data.data.p_data              = data;     
    manuf_data.data.size                = sizeof(data);

    

    init.advdata.name_type               = BLE_ADVDATA_SHORT_NAME;
    init.advdata.short_name_len          = 6;
    init.advdata.include_appearance      = false;
    init.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    init.advdata.p_manuf_specific_data   = &amp;amp;manuf_data;
    

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;

    init.evt_handler = on_adv_evt;

    err_code = ble_advertising_init(&amp;amp;m_advertising, &amp;amp;init);
    APP_ERROR_CHECK(err_code);

    ble_advertising_conn_cfg_tag_set(&amp;amp;m_advertising, APP_BLE_CONN_CFG_TAG);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and Interrupt handler function which changes the advertisement data using ble_advdata_set():-&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void SWI1_IRQHandler(bool radio_evt)
{
    uint32_t err_code;
    ble_advertising_init_t init2;

    if (radio_evt)
    {
        nrf_gpio_pin_toggle(BSP_LED_2); //Toggle the status of the LED on each radio notification event
        
        memset(&amp;amp;init2, 0, sizeof(init2));
        ble_advdata_manuf_data_t manuf_data;
        static int i = 0;
        uint8_t* data[5];
        data[0] = putter(&amp;quot;fghitrf&amp;quot;);
        data[1] = putter(&amp;quot;avbwifq&amp;quot;);
        data[2] = putter(&amp;quot;oiqhjdc&amp;quot;);
        data[3] = putter(&amp;quot;anoirdf&amp;quot;);
        data[4] = putter(&amp;quot;ujhqvnm&amp;quot;);

        manuf_data.company_identifier       = 0xFFFF; // Unregistered company
        i = i%5;
        manuf_data.data.p_data = data[i];


        manuf_data.data.size                = sizeof(data[i]);
        i++;
        
        init2.advdata.name_type               = BLE_ADVDATA_SHORT_NAME;
        init2.advdata.short_name_len          = 6;
        init2.advdata.include_appearance      = false;
        init2.advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        init2.advdata.p_manuf_specific_data   = &amp;amp;manuf_data;

        err_code = ble_advdata_set(&amp;amp;(init2.advdata), NULL);
        APP_ERROR_CHECK(err_code);
    
      
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The putter() is just a function used to store random strings in the data[] array. Here are the outputs which I got:-&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot_5F00_2018_2D00_06_2D00_01_2D00_11_2D00_56_2D00_11_2D00_494_5F00_no.nordicsemi.android.mcp.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is the output which I get when I don&amp;#39;t change the advertisement data. And the images below are the outputs when I change the advertisement data.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot_5F00_2018_2D00_06_2D00_01_2D00_11_2D00_56_2D00_08_2D00_713_5F00_no.nordicsemi.android.mcp.png" /&gt;&amp;nbsp; &amp;nbsp;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot_5F00_2018_2D00_06_2D00_01_2D00_11_2D00_56_2D00_13_2D00_814_5F00_no.nordicsemi.android.mcp.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the Manufacturer data is changing but, I am only getting 4 bytes of data as compared to 11 bytes of the data which I was getting previously.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is the radio_notification_init() function call from the main if it maybe of any help to you.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;radio_notification_init(7, NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE, NRF_RADIO_NOTIFICATION_DISTANCE_5500US);
    &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Incomplete data advertised while changing the advertising data during advertising</title><link>https://devzone.nordicsemi.com/thread/134364?ContentTypeID=1</link><pubDate>Fri, 01 Jun 2018 12:27:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc61e6c5-16d0-4430-9a0b-31cd8ebcdc5d</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Can you share the parts of code that are involved in setting up the initial advertising data, as well as the code involved in setting up the changed advertising data, for me (and others) to have a look at?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>