<?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>Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108231/handle-the-ble-event-in-nrf-connect-sdk</link><description>hi, 
 I am using nRF5340 SoC in my application. I am using BLE in that application. i am beginner to nrf connect sdk so, I have few question regarding BLE implementation. 
 1). In nrf sdk17.1.0, we can handle the ble event and advertisement event using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 Feb 2024 09:17:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108231/handle-the-ble-event-in-nrf-connect-sdk" /><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469969?ContentTypeID=1</link><pubDate>Wed, 21 Feb 2024 09:17:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d11f339e-f246-47f7-ad84-b55b2464103d</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Advertising will automatically stop after connection, you have to restart it automatically if you want it to continue to advertise after connection. You can do this by starting advertising in the callback handler for the connected event.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469930?ContentTypeID=1</link><pubDate>Wed, 21 Feb 2024 05:29:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7dcd54d-52d7-448f-8e8e-f7d1ddf2151d</guid><dc:creator>G gautam</dc:creator><description>&lt;p&gt;hi,&lt;/p&gt;
&lt;p&gt;Thank you for quick response.&lt;/p&gt;
&lt;p&gt;I modify the code as you suggest but in this case advertisement will stop after connection.&lt;/p&gt;
&lt;p&gt;But understand my requirement after connection advertise will not going to stop. advertisement will stop after 1 minute from disconnection happen.&lt;/p&gt;
&lt;p&gt;so my requirement is advertisement will stop after 1 minute from disconnection.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks and regard&lt;/p&gt;
&lt;p&gt;Gautam.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469815?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2024 13:52:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83c111ea-f95e-47cf-a1d4-33122fcd6b3e</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
	if (err) {
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
		return;
	}&lt;/pre&gt;Redefine&amp;nbsp;BT_LE_ADV_CONN_NAME&lt;/p&gt;
&lt;p&gt;with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define BT_LE_ADV_CONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE |BT_LE_ADV_OPT_ONE_TIME,  \
					    BT_LE_ADV_OPT_USE_NAME, \
					    BT_GAP_ADV_FAST_INT_MIN_2, \
					    BT_GAP_ADV_FAST_INT_MAX_2, NULL)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;regards&lt;br /&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469726?ContentTypeID=1</link><pubDate>Tue, 20 Feb 2024 09:20:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8813fc6a-8b34-436a-886a-eace62882c62</guid><dc:creator>G gautam</dc:creator><description>&lt;p&gt;hi jared,&lt;/p&gt;
&lt;p&gt;Here i share the project.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469563?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2024 14:20:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d33b2472-0a4f-4342-a0fa-1f43763c8e24</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/bluetooth/periodic_adv/README.html"&gt;periodic advertising sample&lt;/a&gt; use extended advertising.&lt;/p&gt;
[quote user="G gautam"]I am not start the&amp;nbsp;advertisement after&amp;nbsp;disconnect,&amp;nbsp; its automatically started advertisement . For your rferance&amp;nbsp; i was set advertisement data as below.[/quote]
&lt;p&gt;Can you share your whole project?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469339?ContentTypeID=1</link><pubDate>Sat, 17 Feb 2024 10:57:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cceb7542-3006-48e8-8e51-d61d627c1a85</guid><dc:creator>G gautam</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thenk you for detail replay.&lt;/p&gt;
&lt;p&gt;Can you please suggest &lt;span&gt;extended advertising&amp;nbsp;example?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:150%;"&gt;&lt;strong&gt;How are you restarting the advertisement after a disconnection? Can you show me the code?&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am not start the&amp;nbsp;advertisement after&amp;nbsp;disconnect,&amp;nbsp; its automatically started advertisement . For your rferance&amp;nbsp; i was set advertisement data as below.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const struct bt_data ad[]={
        BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR | BT_LE_AD_LIMITED)),
        BT_DATA_BYTES(BT_DATA_UUID16_ALL,
		        BT_UUID_16_ENCODE(BT_UUID_BAS_VAL),
				BT_UUID_16_ENCODE(BT_UUID_DIS_VAL)),
		//BT_DATA(BT_DATA_MANUFACTURER_DATA, DEVICE_MANUF_NAME, DEVICE_MANUF_NAME_LEN)
};

static const struct bt_data sd[]={
    BT_DATA_BYTES(BT_DATA_UUID128_ALL, CUSTOM_DATA_SERVICE_UUID_VAL),
};&lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And started advertiseing as below&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void bt_ready(void)
{
	int err;

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

	err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
	if (err) {
		printk(&amp;quot;Advertising failed to start (err %d)\n&amp;quot;, err);
		return;
	}
	// adv_value=true;
	printk(&amp;quot;Advertising successfully started\n&amp;quot;);
}&lt;/pre&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I only do this for advertisement. please let me know if i am wrong.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thank you in advance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/469230?ContentTypeID=1</link><pubDate>Fri, 16 Feb 2024 12:32:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31bb3c1d-4481-4191-ba98-667f52017a66</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="G gautam"]&lt;p&gt;&lt;strong&gt;For advertising, exactly what events were you thinking of?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1.&amp;nbsp;&lt;/strong&gt; For advertising, when advertising start i expecting event and also advertisement stop&amp;nbsp; i expecting event. In NRF5 SDK there is one callback function called&amp;nbsp;on_adv_evt().&amp;nbsp;This function will call when advertising event happen such as start advertising and stop advertising. as shown in below snippet .&lt;/p&gt;[/quote]
&lt;p&gt;For this feature you have to use extended advertising API. The extended advertising API allows you to send legacy advertising packets as well. You can use this &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/zephyr/connectivity/bluetooth/api/gap.html#c.bt_le_ext_adv_cb.sent"&gt;callback handler&lt;/a&gt;&amp;nbsp;for that. You can start toggling the LED when you start advertising and stop it once the callback handler is called.&lt;/p&gt;
&lt;p&gt;You can setup it like this:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1708079289974v1.png" alt=" " /&gt;&lt;/p&gt;
[quote user="G gautam"]&lt;strong&gt;2&lt;/strong&gt;. In my custom service i also want event. for example any characteristic will notify i want event and i have to handle that event. Like below snippet from nrf5 sdk.[/quote]
&lt;p&gt;This is shown in the ble_app_hrs sample, see hrs.c:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1708086615931v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1708086587499v3.png" alt=" " /&gt;&lt;/p&gt;
[quote user="G gautam"]&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;strong&gt;3.&lt;/strong&gt;&lt;/span&gt;&amp;nbsp; Another question regarding advertisement is i want stop advertisement after 1(one) minute if central device is not connected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I use this macro in prj.conf file.&amp;nbsp;&amp;nbsp;&lt;strong&gt;CONFIG_BT_LIM_ADV_TIMEOUT=60.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And also set this flag into advertisement parameter. &lt;strong&gt;BT_LE_AD_LIMITED.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;But only one time advertisement was stop when system gets start or reset. Once central device is connected and then disconnected after that advertisement never stop&amp;nbsp;after one minute&lt;/p&gt;[/quote]
&lt;p&gt;How are you restarting the advertisement after a disconnection? Can you show me the code?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/468923?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2024 05:31:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df173c00-911b-43f9-b19b-73c6033adf80</guid><dc:creator>G gautam</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for quick response.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For advertising, exactly what events were you thinking of?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1.&amp;nbsp;&lt;/strong&gt; For advertising, when advertising start i expecting event and also advertisement stop&amp;nbsp; i expecting event. In NRF5 SDK there is one callback function called&amp;nbsp;on_adv_evt().&amp;nbsp;This function will call when advertising event happen such as start advertising and stop advertising. as shown in below snippet .&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_cus_evt(ble_cus_t     * p_cus_service,
                       ble_cus_evt_t * p_evt, ble_evt_t  *evt)
{
    ret_code_t err_code;

    uint8_t bleWriteBuffer[10] = {0};

    switch(p_evt-&amp;gt;evt_type)
    {
        case BLE_CUS_EVT_CONNECTED:
             err_code = app_timer_start(m_comm_timer_id, DATA_UPDATE_1SEC_INTERVAL, NULL);
             APP_ERROR_CHECK(err_code);
            break;
            
        case BLE_CUS_EVT_DISCONNECTED:
             nrf_gpio_pin_clear(GNSS_EN_PIN);
             err_code = app_timer_stop(m_comm_timer_id);
             APP_ERROR_CHECK(err_code);
            break;

        case BLE_CUS_EVT_NFC_CHAR_WRITE:
            memset(bleWriteBuffer,0, sizeof(bleWriteBuffer));
            BC_BleWriteHandler(p_cus_service,evt,bleWriteBuffer);
            BCMi_GeneralCmdCode(bleWriteBuffer);
            break;

        case BLE_CUS_EVT_NFC_CHAR_NOTIFICATION_ENABLE:
             //err_code = app_timer_start(m_nfc_timer_id, NOTIFICATION_INTERVAL, NULL);
             //APP_ERROR_CHECK(err_code);
             _nfc_flag = true;
            break;
        
        case BLE_CUS_EVT_NFC_CHAR_NOTIFICATION_DISABLE:
            //err_code = app_timer_stop(m_nfc_timer_id);
            //APP_ERROR_CHECK(err_code);
            _nfc_flag = false;
            break;

        case BLE_CUS_EVT_ACC_CHAR_READ:
            break;

        case BLE_CUS_EVT_ACC_CHAR_NOTIFICATION_ENABLE:
             err_code = app_timer_start(m_acc_timer_id, ACC_DATA_INTERVAL, NULL);
             APP_ERROR_CHECK(err_code);
            break;
        

        default:
              // No implementation needed.
            break;
    }
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So where i register this type of callback function.&lt;/p&gt;
&lt;p&gt;Using this event i want to start and stop blink led for advertising also when advertising will stop i want to system goes into sleep mode. That what i am expecting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2&lt;/strong&gt;. In my custom service i also want event. for example any characteristic will notify i want event and i have to handle that event. Like below snippet from nrf5 sdk.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;strong&gt;3.&lt;/strong&gt;&lt;/span&gt;&amp;nbsp; Another question regarding advertisement is i want stop advertisement after 1(one) minute if central device is not connected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I use this macro in prj.conf file.&amp;nbsp;&amp;nbsp;&lt;strong&gt;CONFIG_BT_LIM_ADV_TIMEOUT=60.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And also set this flag into advertisement parameter. &lt;strong&gt;BT_LE_AD_LIMITED.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;But only one time advertisement was stop when system gets start or reset. Once central device is connected and then disconnected after that advertisement never stop&amp;nbsp;after one minute.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So what is the right way to define timeout for advertisement which works in both condition. If you have any example code regarding that please share with me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/468883?ContentTypeID=1</link><pubDate>Wed, 14 Feb 2024 15:31:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b5646f6-b93e-48d7-820d-e40f0c790d44</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Some events such as connected and disconnected you have to pass a specific callback handler like this:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1707924674905v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;For advertising, exactly what events were you thinking of?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/468764?ContentTypeID=1</link><pubDate>Wed, 14 Feb 2024 09:35:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f956c3b3-d1f3-42c9-ad72-c51103f4470c</guid><dc:creator>G gautam</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for response,&lt;/p&gt;
&lt;p&gt;I already refer this course but i didn&amp;#39;t get my answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handle the BLE Event in nRF connect SDK?</title><link>https://devzone.nordicsemi.com/thread/468550?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2024 10:21:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ca9c63f-ddd3-4ea7-aaa8-e6e04c2546bd</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please go trough our &lt;a href="https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/"&gt;Bluetooth Low Energy Fundamental course for nRF Connect SDK,&lt;/a&gt; your questions should be answered in that course,&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>