<?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>ble advertising start probelm</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19078/ble-advertising-start-probelm</link><description>In my application, I execute below code to start advertise when a button is pressed 
 err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
 APP_ERROR_CHECK(err_code);
 
 When I press the button for more than once, the system reset. It seems that when</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Sep 2018 15:05:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19078/ble-advertising-start-probelm" /><item><title>RE: ble advertising start probelm</title><link>https://devzone.nordicsemi.com/thread/149490?ContentTypeID=1</link><pubDate>Wed, 19 Sep 2018 15:05:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e003623e-5a95-4200-af00-91b09ff06e71</guid><dc:creator>Joao Teixeira</dc:creator><description>&lt;p&gt;Please, take also a look in the answer &lt;a title="nrf52 reconnection problem" href="https://devzone.nordicsemi.com/f/nordic-q-a/31124/nrf52-reconnection-problem"&gt;posted here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble advertising start probelm</title><link>https://devzone.nordicsemi.com/thread/73779?ContentTypeID=1</link><pubDate>Thu, 19 Jan 2017 08:25:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04bf6f80-e3a1-4f64-87b3-b25cef14af34</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry, there was a typo in the code. It should be: &lt;code&gt;p_ble_evt-&amp;gt;evt.gap_evt.params.timeout.src&lt;/code&gt;. I updated the code after posting the original reply (you can click the &lt;em&gt;updated [time]&lt;/em&gt; on the answer to see changelog), maybe you did not get an update mail.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble advertising start probelm</title><link>https://devzone.nordicsemi.com/thread/73778?ContentTypeID=1</link><pubDate>Thu, 19 Jan 2017 02:07:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62b805b4-5697-41c7-a9b9-4685223d842b</guid><dc:creator>Fiske</dc:creator><description>&lt;p&gt;When I compile the code, it generate below error at if (p_ble_evt-&amp;gt;evt.gap_evt.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING). Note that I am using nRF5_SDK_12.0.0 ble_app_uart example&lt;/p&gt;
&lt;p&gt;Error[Pe136]: struct &amp;quot;&amp;quot; has no field &amp;quot;timeout&amp;quot;&lt;/p&gt;
&lt;p&gt;Besides, why the answer post at here is different from the one shown in my email.&lt;/p&gt;
&lt;p&gt;in my email the event case is
case BLE_GATTC_EVT_TIMEOUT:&lt;/p&gt;
&lt;p&gt;while at the web page it is
case BLE_GAP_EVT_TIMEOUT:&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble advertising start probelm</title><link>https://devzone.nordicsemi.com/thread/73777?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 11:58:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f060fc7c-bd93-4d63-b500-55fc9935ce06</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;As described in &lt;a href="https://devzone.nordicsemi.com/question/80959/check-if-currently-advertising/?answer=81013#post-id-81013"&gt;this answer&lt;/a&gt;, there is no way of checking the current state of advertising. You should implement a flag in your application where you keep track of whether you are advertising or not.&lt;/p&gt;
&lt;p&gt;If you have a connectable peripheral with two buttons, one for starting and one for stopping advertisingcould, an example could be like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;bool is_advertising = false;

void button_1_handler(void) // Start advertising
{
	if(!is_advertising)
	{
		err_code = sd_ble_gap_adv_start();
		if (err_code == NRF_SUCCESS){
			is_advertising = true;
		}
		else{
			APP_ERROR_CHECK(err_code);
		}
	}
}

void button_2_handler(void) // Stop advertising
{
	if(is_advertising)
	{
		err_code = sd_ble_gap_adv_stop();
		if (err_code == NRF_SUCCESS){
			is_advertising = false;
		}
		else{
			APP_ERROR_CHECK(err_code);
		}
	}
}

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    uint32_t err_code;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
			is_advertising = false; // Softdevice stops advertising when in a connection
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            if(!is_advertising)
			{
				err_code = sd_ble_gap_adv_start(); // Start advertising when no longer connected
				if(err_code == NRF_SUCCESS){
					is_advertising = true;
				}
				else{
					APP_ERROR_CHECK(err_code);
				}
			}
            break;

        case BLE_GAP_EVT_TIMEOUT:
            if (p_ble_evt-&amp;gt;evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING)
			{
				is_advertising = false; // If advertising times out
			}
            break;
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Remember that you need to keep track of the advertising state if you start or stop advertising elsewhere in your code.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>