<?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 can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/32298/how-can-i-update-advertising-data-without-restarting-advertising-process</link><description>Currently, if I want to update the advertising data, firstly, I use sd_ble_gap_adv_stop , then update the advertising data with ble_advdata_service_data_t , then advertising_init , at the end, ble_advertising_start . 
 Is it possible update the advertising</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 19 Mar 2018 08:25:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/32298/how-can-i-update-advertising-data-without-restarting-advertising-process" /><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124916?ContentTypeID=1</link><pubDate>Mon, 19 Mar 2018 08:25:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fecf2a73-652b-4a0c-bfa4-60cb1e356996</guid><dc:creator>venerley</dc:creator><description>&lt;p&gt;My work was based on the &lt;em&gt;&lt;strong&gt;ble_app_template&lt;/strong&gt;&lt;/em&gt; example so I inherited the setup process.&amp;nbsp;There could be some effect on the order of setup.&lt;/p&gt;
&lt;p&gt;Anyway this is my setup process, almost identical to the&amp;nbsp;&lt;em&gt;&lt;strong&gt;ble_app_template&lt;/strong&gt;&lt;/em&gt;&lt;span&gt; example. However looks like you are also providing the contents of the advertising packet, which I have delegated to the stack. In my case it wasn&amp;#39;t necessary to stop advertising, change scan response, start advertising.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
    bool erase_bonds;

    // Sets up nrf_log
    log_init();
    // this is where the timer module is initialised &amp;amp; new timers created.
    timers_init();
    // sets up buttons &amp;amp; leds. Note: the value of erase_bonds is determined
    // by the button pressed when the board boots.
    buttons_leds_init(&amp;amp;erase_bonds);

    // configure the softdevice
    ble_stack_init();

    // set all the gap parameters, timings and the appearance.
    gap_params_init();

    //
    gatt_init();

    services_init();
    advertising_init();
    conn_params_init();
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Template example started.\r\n&amp;quot;);
    application_timers_start();

    advertising_start();

    // set up the uart
    uart_init();

    // Enter main loop.
    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }
}&lt;/pre&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124907?ContentTypeID=1</link><pubDate>Mon, 19 Mar 2018 07:51:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:187b54ce-78e4-4132-9b0a-34d2b9edcc34</guid><dc:creator>Nijat</dc:creator><description>&lt;p&gt;Yes, all steps are working. But I cannot update the Advertising Data without these procedure : stopAdv, initAdv &amp;amp; startAdv.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I used&amp;nbsp;&lt;em&gt;&lt;strong&gt;sd_ble_gap_adv_data_set&lt;/strong&gt;&lt;/em&gt;, but it returns error 7 which represent&amp;nbsp;&lt;span&gt;Invalid_PARAMS&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;When we initAdv, it calls&amp;nbsp;&lt;em&gt;&lt;strong&gt;sd_ble_gap_adv_data_set&lt;/strong&gt;&lt;/em&gt;, but the parameter p_data is an p_encoded_advdata. So using directly&amp;nbsp;&lt;em&gt;&lt;strong&gt;sd_ble_gap_adv_data_set&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;returns Invalid_DATA, but if I put&amp;nbsp;&lt;span&gt;p_encoded_advdata&lt;/span&gt;&lt;span&gt;&amp;nbsp;as parameters it returns&amp;nbsp;Invalid_PARAMS. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also the type of&amp;nbsp;Invalid_DATA is ble_advdata_t.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124872?ContentTypeID=1</link><pubDate>Sat, 17 Mar 2018 20:23:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5098cab-a175-4585-a44a-efee09345e38</guid><dc:creator>venerley</dc:creator><description>&lt;p&gt;Absolutely right. You might want to endure the pain of the tutorials on advertising and setting up a service (the tutorials use SDK11). If you set up a service, as shown in the Service tutorial then the stack will handle adverting it and you only need worry about managing the scan response. So I did 4 things:&lt;/p&gt;
&lt;p&gt;1) Set up up a service as describe in the Service tutorial.&lt;/p&gt;
&lt;p&gt;2) Used that service setting up advertising &amp;amp; noting that setting the contents of the entire&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;ble_adv_modes_config_t &lt;/strong&gt;&lt;/em&gt;to zero&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_advdata_t          advdata;
    ble_adv_modes_config_t options;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&amp;amp;advdata, 0, sizeof(advdata));

    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    //advdata.include_appearance      = true;
    advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;

    memset(&amp;amp;options, 0, sizeof(options));
    err_code = ble_advertising_init(&amp;amp;advdata, NULL, /*NULL*/ &amp;amp;options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Start advertising:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void advertising_start(void)
{
    // Initialize advertising parameters (used when starting advertising).
	ble_gap_adv_params_t m_adv_params;
    memset(&amp;amp;m_adv_params, 0, sizeof(m_adv_params));

    m_adv_params.type			= BLE_GAP_ADV_TYPE_ADV_SCAN_IND; 	//BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
    m_adv_params.p_peer_addr 	= NULL;								// Undirected advertisement.
    m_adv_params.fp				= BLE_GAP_ADV_FP_ANY; 				/**&amp;lt; Allow scan requests and connect requests from any device. */
    m_adv_params.interval		= NON_CONNECTABLE_ADV_INTERVAL; 	// setting the advertising interval to 100ms.
    m_adv_params.timeout		= APP_CFG_NON_CONN_ADV_TIMEOUT; 	// this define is 0, meaning that advertising will never timeout.

    ret_code_t err_code = sd_ble_gap_adv_start(&amp;amp;m_adv_params, BLE_CONN_CFG_TAG_DEFAULT);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Update the scan response when required&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SR_LEN 15

static void scan_resp_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
	static uint8_t sr_data[SR_LEN];
	sr_data[00] = SR_LEN - 1;		// Ad length- length of the data field not including the length field (to SR_LEN)!
	sr_data[01] = 0xff;				// Ad type	- Manufacturers specific data
	sr_data[02] = 0xff;				// Ad 		- Manufacturers ID
	sr_data[03] = 0xff;				// Ad 		- Manufacturers ID


	/*
		Update the sr_data array with your new data - bytes 4 -&amp;gt; 14
		But make sure you get the value of the length correct otherwise you’ll get a fatal error!
		err_code = 9 NRF_ERROR_INVALID_LENGTH
		Just 15 bytes are used here however you can use up to 31.
	 */   

    ret_code_t err_code = sd_ble_gap_adv_data_set(NULL, 0, sr_data, sizeof(sr_data));
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;hope this helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124850?ContentTypeID=1</link><pubDate>Sat, 17 Mar 2018 04:03:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd7773d6-7875-4776-8222-68494b43fa51</guid><dc:creator>Nijat</dc:creator><description>&lt;p&gt;Also, the&amp;nbsp;&lt;em&gt;&lt;strong&gt;sr_data is Encoded Data ?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124845?ContentTypeID=1</link><pubDate>Sat, 17 Mar 2018 01:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:173a4d88-8163-4385-9069-75294b6dc5ec</guid><dc:creator>Nijat</dc:creator><description>&lt;p&gt;The&amp;nbsp;p_data can be&amp;nbsp;uint8_array_t type ? Is it an array ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124844?ContentTypeID=1</link><pubDate>Sat, 17 Mar 2018 01:46:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f1174ed-8d89-405f-90ce-f31c3d1e5484</guid><dc:creator>Nijat</dc:creator><description>&lt;p&gt;&lt;em&gt;&lt;strong&gt;p_sr_data&amp;nbsp;is the scanned data, right ?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;And&amp;nbsp;p_data is the&amp;nbsp;&lt;span&gt;advertising data.&lt;/span&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124655?ContentTypeID=1</link><pubDate>Thu, 15 Mar 2018 19:36:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3af25200-d8e1-4777-9c83-1e1c9acae18d</guid><dc:creator>venerley</dc:creator><description>&lt;p&gt;I got it working by calling&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;ret_code_t err_code = sd_ble_gap_adv_data_set(NULL, 0, sr_data, sizeof(sr_data));&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;whenever the scan response data needed updating, where I managed the layout of the data within array&amp;nbsp;&lt;strong&gt;&lt;em&gt;sr_data&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I update advertising data without restarting advertising process ?</title><link>https://devzone.nordicsemi.com/thread/124560?ContentTypeID=1</link><pubDate>Thu, 15 Mar 2018 11:36:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc8cbbca-c3b6-4181-8c03-a29b13e98f55</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;It is not necessary to stop advertising when updating the advertising data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The easiest way to update the advertising data is to call ble_adv_data_set() in ble_advertising.h/.c.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>