<?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 switch the functions between beacon advertising to connectable advertising?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30823/how-to-switch-the-functions-between-beacon-advertising-to-connectable-advertising</link><description>Hello, I want to switch the functions between beacon advertising to connectable advertising. 
 In the code , it can be initial as a beacon advertising or normal advertising ( connectable advertising), then switch to another. 
 My main code as below: </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 02 Mar 2018 05:51:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30823/how-to-switch-the-functions-between-beacon-advertising-to-connectable-advertising" /><item><title>RE: How to switch the functions between beacon advertising to connectable advertising?</title><link>https://devzone.nordicsemi.com/thread/122543?ContentTypeID=1</link><pubDate>Fri, 02 Mar 2018 05:51:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5331a24-9c04-428e-bc1f-509610920ec2</guid><dc:creator>cadillacxlr</dc:creator><description>&lt;p&gt;Hello, main code as belows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for starting advertising.
 */
static void advertising_start(bool erase_bonds)
{
    if (erase_bonds == true)
    {
        delete_bonds();
        // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED evetnt
    }
    else
    {
        ret_code_t err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);

        APP_ERROR_CHECK(err_code);
    }
}



void systick_handler(void * p_context)
{
	
}

void app_ble_advertising_init(void)
{
	bool erase_bonds;
	
	buttons_leds_init(&amp;amp;erase_bonds);
    ble_stack_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();
	
    // Start execution.
    NRF_LOG_INFO(&amp;quot;Template example started.&amp;quot;);
    application_timers_start();

    advertising_start(erase_bonds);
}

void change_to_app_ble_advertising_init(void)
{
	bool erase_bonds;
	
	gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
	
    advertising_start(erase_bonds);
}

void app_ble_beacon_init(void)
{
	ble_stack_init();
	
	beacon_advertising_init();	
	beacon_advertising_start();
}

void change_to_app_ble_beacon_init(void)
{
	beacon_advertising_init();
	beacon_advertising_start();
}

/**@brief Function for application main entry.
 */

uint8_t press_flag_3, press_flag_4;
int main(void)
{
    bool erase_bonds;
	
    // Initialize.
    log_init();
    timers_init();

	ble_stack_init();
	
	application_timers_start();
    peer_manager_init();
	
	while(1)
	{
		change_to_app_ble_advertising_init();
		nrf_delay_ms(2000);
		
		sd_ble_gap_adv_stop();
		nrf_delay_ms(200);
		
		change_to_app_ble_beacon_init();
		nrf_gpio_pin_write(LED_2,0);
		nrf_delay_ms(2000);
		
		sd_ble_gap_adv_stop();
		nrf_delay_ms(200);
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch the functions between beacon advertising to connectable advertising?</title><link>https://devzone.nordicsemi.com/thread/122042?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 06:21:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dae27512-a5b0-4d1f-aa46-228d9f367070</guid><dc:creator>rraa</dc:creator><description>&lt;p&gt;can you share fixed code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch the functions between beacon advertising to connectable advertising?</title><link>https://devzone.nordicsemi.com/thread/122038?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 05:47:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e19d4755-23f9-4793-a370-efa46db99854</guid><dc:creator>cadillacxlr</dc:creator><description>&lt;p&gt;Thanks for your reply! And I notice that if the function &amp;quot;ble_stack_init()&amp;quot; is called twice, the chip will restart.&lt;/p&gt;
&lt;p&gt;Now in my code, I can switch the two advertising mode smoothly. Thank you very much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to switch the functions between beacon advertising to connectable advertising?</title><link>https://devzone.nordicsemi.com/thread/121988?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 15:41:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e8b8683-af33-484d-857c-58ace99cedd5</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey cadillacxlr,&lt;/p&gt;
&lt;p&gt;You need to stop advertisements by calling&amp;nbsp;&lt;a title="sd_ble_gap_adv_stop" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v5.0.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html?cp=2_3_1_1_0_2_1_2_4#gaa88eea8e9e95dd96a7633e2c62f3ce16"&gt;sd_ble_gap_adv_stop&lt;/a&gt;,&amp;nbsp; change the advertisement data with&amp;nbsp;&lt;a title="sd_ble_gap_adv_data_set" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v5.0.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html?cp=2_3_1_1_0_2_1_2_2#gaddbb12e078d536ef2e93b41d77ff6243"&gt;sd_ble_gap_adv_data_set&lt;/a&gt;, and finnaly restart advertisements with&amp;nbsp;&lt;a title="sd_ble_gap_adv_start" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v5.0.0/group___b_l_e___g_a_p___f_u_n_c_t_i_o_n_s.html?cp=2_3_1_1_0_2_1_2_3#ga241191b3fa20a5c20a60a088240a1dfa"&gt;sd_ble_gap_adv_start&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>