<?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_app_uart peripheral and ble_app_uart central merge.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72680/ble_app_uart-peripheral-and-ble_app_uart-central-merge</link><description>I am using the nRF52840 board and nRF5 SDK 17.0.2. 
 I am trying to merge ble_app_uart central with the ble_app_uart peripheral. After made the requird changes(sdk_config.h) I have got some errors. 
 1. BLE_NUS_EVT_COMM_STARTED is not triggering when</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Mar 2021 15:19:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72680/ble_app_uart-peripheral-and-ble_app_uart-central-merge" /><item><title>RE: ble_app_uart peripheral and ble_app_uart central merge.</title><link>https://devzone.nordicsemi.com/thread/300199?ContentTypeID=1</link><pubDate>Tue, 16 Mar 2021 15:19:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af701e46-5a3f-4490-9e3d-e30fb0ff884f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="AKV"]&lt;p&gt;&lt;span&gt;My requirement is&amp;nbsp;the device should connect only one peripheral at a time. and will not connect with another central device.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What all changes have to make in this code?&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;You do not need any changes for that. The example implements on peripheral link and once central link.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_app_uart peripheral and ble_app_uart central merge.</title><link>https://devzone.nordicsemi.com/thread/299934?ContentTypeID=1</link><pubDate>Mon, 15 Mar 2021 17:24:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca9fe8c6-08c0-4303-996f-a9aa0405f4ae</guid><dc:creator>AKV</dc:creator><description>&lt;p&gt;Hi Einar&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/NordicPlayground/nrf52-ble-app-uart-relay"&gt;nrf52-ble-app-uart-relay&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This example combines the ble_app_uart and ble_app_uart_c examples into one, effectively acting as a NUS relay between one central/client device and one peripheral/server device. It will automatically connect to any NUS peripheral in the area, and relay information back and forth if a NUS central also connects to the relay.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My requirement is&amp;nbsp;the device should connect only one peripheral at a time. and will not connect with another central device.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What all changes have to make in this code?&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: ble_app_uart peripheral and ble_app_uart central merge.</title><link>https://devzone.nordicsemi.com/thread/299805?ContentTypeID=1</link><pubDate>Mon, 15 Mar 2021 13:29:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3bc13b6-da7f-4687-b9f6-4bac65e60e21</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please refer to &lt;a href="https://github.com/NordicPlayground/nrf52-ble-app-uart-relay"&gt;the nrf52-ble-app-uart-relay example&lt;/a&gt;, which is essentially what you want to do (merge the NUS central and peripheral examples).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_app_uart peripheral and ble_app_uart central merge.</title><link>https://devzone.nordicsemi.com/thread/299502?ContentTypeID=1</link><pubDate>Fri, 12 Mar 2021 14:19:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2a6ff4c-9f9f-4438-943f-c777add81fd8</guid><dc:creator>AKV</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define APP_BLE_CONN_CFG_TAG            1                                           /**&amp;lt; A tag identifying the SoftDevice BLE configuration. */

#define DEVICE_NAME                     &amp;quot;Nordic_UART&amp;quot;                               /**&amp;lt; Name of device. Will be included in the advertising data. */
#define NUS_SERVICE_UUID_TYPE           BLE_UUID_TYPE_VENDOR_BEGIN                  /**&amp;lt; UUID type for the Nordic UART Service (vendor specific). */

#define APP_BLE_OBSERVER_PRIO           3                                           /**&amp;lt; Application&amp;#39;s BLE observer priority. You shouldn&amp;#39;t need to modify this value. */

#define APP_ADV_INTERVAL                64                                          /**&amp;lt; The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */

#define APP_ADV_DURATION                18000                                       /**&amp;lt; The advertising duration (180 seconds) in units of 10 milliseconds. */

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(7.5, UNIT_1_25_MS)             /**&amp;lt; Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(7.5, UNIT_1_25_MS)             /**&amp;lt; Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */


#define SLAVE_LATENCY                   0                                           /**&amp;lt; Slave latency. */
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)             /**&amp;lt; Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000)                       /**&amp;lt; Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)                      /**&amp;lt; Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                           /**&amp;lt; Number of attempts before giving up the connection parameter negotiation. */

#define DEAD_BEEF                       0xDEADBEEF                                  /**&amp;lt; Value used as error code on stack dump, can be used to identify stack location on stack unwind. */

#define UART_TX_BUF_SIZE                256                                         /**&amp;lt; UART TX buffer size. */
#define UART_RX_BUF_SIZE                256                                         /**&amp;lt; UART RX buffer size. */



static uint8_t m_gap_role     = BLE_GAP_ROLE_INVALID;

BLE_NUS_C_DEF(m_ble_nus_c);                                             /**&amp;lt; BLE Nordic UART Service (NUS) client instance. */
//NRF_BLE_GATT_DEF(m_gatt);                                               /**&amp;lt; GATT module instance. */
BLE_DB_DISCOVERY_DEF(m_db_disc);                                        /**&amp;lt; Database discovery module instance. */
NRF_BLE_SCAN_DEF(m_scan);                                               /**&amp;lt; Scanning Module instance. */
NRF_BLE_GQ_DEF(m_ble_gatt_queue,                                        /**&amp;lt; BLE GATT Queue instance. */
               NRF_SDH_BLE_CENTRAL_LINK_COUNT,
               NRF_BLE_GQ_QUEUE_SIZE);


/**@brief NUS UUID. */
static ble_uuid_t const m_nus_uuid =
{
    .uuid = BLE_UUID_NUS_SERVICE,
    .type = NUS_SERVICE_UUID_TYPE
};




BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);                                   /**&amp;lt; BLE NUS service instance. */
NRF_BLE_GATT_DEF(m_gatt);                                                           /**&amp;lt; GATT module instance. */
NRF_BLE_QWR_DEF(m_qwr);                                                             /**&amp;lt; Context for the Queued Write module.*/
BLE_ADVERTISING_DEF(m_advertising);                                                 /**&amp;lt; Advertising module instance. */

static uint16_t   m_conn_handle          = BLE_CONN_HANDLE_INVALID;                 /**&amp;lt; Handle of the current connection. */
static uint16_t   m_ble_nus_max_data_len = BLE_GATT_ATT_MTU_DEFAULT - 3;            /**&amp;lt; Maximum length of data (in bytes) that can be transmitted to the peer by the Nordic UART service module. */
static ble_uuid_t m_adv_uuids[]          =                                          /**&amp;lt; Universally unique service identifier. */
{
    {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
};

static void gap_params_init(void)
{
    uint32_t                err_code;
    ble_gap_conn_params_t   gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;sec_mode);

    err_code = sd_ble_gap_device_name_set(&amp;amp;sec_mode,
                                          (const uint8_t *) DEVICE_NAME,
                                          strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    memset(&amp;amp;gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency     = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&amp;amp;gap_conn_params);
    APP_ERROR_CHECK(err_code);
//    NRF_LOG_INFO(&amp;quot;gap_params error code %d \n&amp;quot;,err_code); 
}
static void services_init(void)
{
    uint32_t           err_code;
    ble_nus_init_t     nus_init;
    nrf_ble_qwr_init_t qwr_init = {0};

    // Initialize Queued Write Module.
    qwr_init.error_handler = nrf_qwr_error_handler;

    err_code = nrf_ble_qwr_init(&amp;amp;m_qwr, &amp;amp;qwr_init);
    APP_ERROR_CHECK(err_code);

    // Initialize NUS.
    memset(&amp;amp;nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = nus_data_handler;

    err_code = ble_nus_init(&amp;amp;m_nus, &amp;amp;nus_init);
    APP_ERROR_CHECK(err_code);
}

static void conn_params_init(void)
{
    uint32_t               err_code;
    ble_conn_params_init_t cp_init;

    memset(&amp;amp;cp_init, 0, sizeof(cp_init));

    cp_init.p_conn_params                  = NULL;
    cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
    cp_init.next_conn_params_update_delay  = NEXT_CONN_PARAMS_UPDATE_DELAY;
    cp_init.max_conn_params_update_count   = MAX_CONN_PARAMS_UPDATE_COUNT;
    cp_init.start_on_notify_cccd_handle    = BLE_GATT_HANDLE_INVALID;
    cp_init.disconnect_on_fail             = false;
    cp_init.evt_handler                    = on_conn_params_evt;
    cp_init.error_handler                  = conn_params_error_handler;

    err_code = ble_conn_params_init(&amp;amp;cp_init);
    APP_ERROR_CHECK(err_code);
}
static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    uint32_t err_code;

    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
            APP_ERROR_CHECK(err_code);
            break;
        case BLE_ADV_EVT_IDLE:
            sleep_mode_enter();
            break;
        default:
            break;
    }
}
static void on_ble_gap_evt_connected(ble_gap_evt_t const * p_gap_evt)
{
    ret_code_t err_code;

    m_conn_handle = p_gap_evt-&amp;gt;conn_handle;
    m_gap_role    = p_gap_evt-&amp;gt;params.connected.role;

    if (m_gap_role == BLE_GAP_ROLE_PERIPH)
    {
        NRF_LOG_INFO(&amp;quot;Connected as a peripheral.m_conn_handle %d: &amp;quot;,m_conn_handle);

        err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        APP_ERROR_CHECK(err_code);

        //m_conn_handle = p_gap_evt-&amp;gt;evt.gap_evt.conn_handle;
        err_code = nrf_ble_qwr_conn_handle_assign(&amp;amp;m_qwr, m_conn_handle);        
        APP_ERROR_CHECK(err_code);
    }
    else if (m_gap_role == BLE_GAP_ROLE_CENTRAL)
    {
        NRF_LOG_INFO(&amp;quot;Connected as a central.&amp;quot;);

        err_code = ble_nus_c_handles_assign(&amp;amp;m_ble_nus_c, m_conn_handle, NULL);
        APP_ERROR_CHECK(err_code);

        //err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        //APP_ERROR_CHECK(err_code);

        // start discovery of services. The NUS Client waits for a discovery result
        err_code = ble_db_discovery_start(&amp;amp;m_db_disc, m_conn_handle);
        APP_ERROR_CHECK(err_code);
    }

    
}
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO(&amp;quot;Connected&amp;quot;);
            on_ble_gap_evt_connected(p_gap_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected&amp;quot;);
            // LED indication will be changed when advertising starts.
            m_conn_handle = BLE_CONN_HANDLE_INVALID;

            break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_INFO(&amp;quot;PHY update request.&amp;quot;);
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;phys);
            APP_ERROR_CHECK(err_code);
        } 
        break;

        case BLE_GAP_EVT_PHY_UPDATE:
              NRF_LOG_INFO(&amp;quot;\r\nBLE_GAP_EVT_PHY_UPDATE rx_phy: %d tx_phy: %d \r\n&amp;quot;,p_ble_evt-&amp;gt;evt.gap_evt.params.phy_update.rx_phy,p_ble_evt-&amp;gt;evt.gap_evt.params.phy_update.tx_phy);
          break;
        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
            // No system attributes have been stored.
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTC_EVT_TIMEOUT:
              NRF_LOG_INFO(&amp;quot;BLE_GATTC_EVT_TIMEOUT..\r\n&amp;quot;);
            // Disconnect on GATT Client timeout event.
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_TIMEOUT:
              NRF_LOG_INFO(&amp;quot;BLE_GATTS_EVT_TIMEOUT..\r\n&amp;quot;);
            // Disconnect on GATT Server timeout event.
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GAP_EVT_CONN_PARAM_UPDATE:
            NRF_LOG_INFO(&amp;quot;BLE_GAP_EVT_CONN_PARAM_UPDATE..min %d: max %d:\r\n&amp;quot;,p_ble_evt-&amp;gt; evt.gap_evt.params.conn_param_update.conn_params.min_conn_interval, p_ble_evt-&amp;gt; evt.gap_evt.params.conn_param_update.conn_params.max_conn_interval);
            break;
        case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
            NRF_LOG_INFO(&amp;quot;BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST..\r\n&amp;quot;);
            break;



        default:
            // No implementation needed.
            break;
    }
}
static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
    APP_ERROR_CHECK(err_code);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}
/**@brief Function for handling events from the GATT library. */
void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
{
    if ((m_conn_handle == p_evt-&amp;gt;conn_handle) &amp;amp;&amp;amp; (p_evt-&amp;gt;evt_id == NRF_BLE_GATT_EVT_ATT_MTU_UPDATED))
    {
        m_ble_nus_max_data_len = p_evt-&amp;gt;params.att_mtu_effective - OPCODE_LENGTH - HANDLE_LENGTH;
        NRF_LOG_INFO(&amp;quot;Data len is set to 0x%X(%d)&amp;quot;, m_ble_nus_max_data_len, m_ble_nus_max_data_len);
    }
    NRF_LOG_DEBUG(&amp;quot;ATT MTU exchange completed. central 0x%x peripheral 0x%x&amp;quot;,
                  p_gatt-&amp;gt;att_mtu_desired_central,
                  p_gatt-&amp;gt;att_mtu_desired_periph);
}


/**@brief Function for initializing the GATT library. */
void gatt_init(void)
{
    ret_code_t err_code;

    err_code = nrf_ble_gatt_init(&amp;amp;m_gatt, gatt_evt_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_gatt_att_mtu_periph_set(&amp;amp;m_gatt, NRF_SDH_BLE_GATT_MAX_MTU_SIZE);
    APP_ERROR_CHECK(err_code);

     err_code = nrf_ble_gatt_att_mtu_central_set(&amp;amp;m_gatt, NRF_SDH_BLE_GATT_MAX_MTU_SIZE);
    APP_ERROR_CHECK(err_code);
}

static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;

    memset(&amp;amp;init, 0, sizeof(init));

    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = false;
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;

    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;

    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
    init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
    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);
}
static void advertising_start(void)
{
    NRF_LOG_INFO(&amp;quot;advertising start.&amp;quot;);
    uint32_t err_code = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
}
static void scan_start(void)
{
    ret_code_t ret;
    NRF_LOG_INFO(&amp;quot;Scan Start.&amp;quot;);

    ret = nrf_ble_scan_start(&amp;amp;m_scan);
    APP_ERROR_CHECK(ret);

//    ret = bsp_indication_set(BSP_INDICATE_SCANNING);
//    APP_ERROR_CHECK(ret);
}

/**@brief Function for handling Scanning Module events.
 */
static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;

    switch(p_scan_evt-&amp;gt;scan_evt_id)
    {
         case NRF_BLE_SCAN_EVT_CONNECTING_ERROR:
         {
              
              err_code = p_scan_evt-&amp;gt;params.connecting_err.err_code;
              NRF_LOG_INFO(&amp;quot;Scan Connecting Error %d:&amp;quot;,err_code);
              APP_ERROR_CHECK(err_code);
              
         } 
         break;

         case NRF_BLE_SCAN_EVT_CONNECTED:
         {
              ble_gap_evt_connected_t const * p_connected =
                               p_scan_evt-&amp;gt;params.connected.p_connected;
             // Scan is automatically stopped by the connection.
             NRF_LOG_INFO(&amp;quot;Connecting to target %02x%02x%02x%02x%02x%02x&amp;quot;,
                      p_connected-&amp;gt;peer_addr.addr[0],
                      p_connected-&amp;gt;peer_addr.addr[1],
                      p_connected-&amp;gt;peer_addr.addr[2],
                      p_connected-&amp;gt;peer_addr.addr[3],
                      p_connected-&amp;gt;peer_addr.addr[4],
                      p_connected-&amp;gt;peer_addr.addr[5]
                      );
         } 
         break;

         case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
         {
             NRF_LOG_INFO(&amp;quot;Scan timed out.&amp;quot;);
             scan_start();
         }
        break;

        case NRF_BLE_SCAN_EVT_WHITELIST_ADV_REPORT:
             NRF_LOG_INFO(&amp;quot;Adv report.&amp;quot;);
        break;

        case NRF_BLE_SCAN_EVT_NOT_FOUND:
             NRF_LOG_INFO(&amp;quot;Scan evt not found.&amp;quot;);
        break;

        case NRF_BLE_SCAN_EVT_FILTER_MATCH:
             NRF_LOG_INFO(&amp;quot;scan event filter match.&amp;quot;);
        break;

        default:
        
        break;
    }
}

static void db_disc_handler(ble_db_discovery_evt_t * p_evt)
{
    ble_nus_c_on_db_disc_evt(&amp;amp;m_ble_nus_c, p_evt);
}


/** @brief Function for initializing the database discovery module. */
static void db_discovery_init(void)
{
    ble_db_discovery_init_t db_init;

    memset(&amp;amp;db_init, 0, sizeof(ble_db_discovery_init_t));

    db_init.evt_handler  = db_disc_handler;
    db_init.p_gatt_queue = &amp;amp;m_ble_gatt_queue;

    ret_code_t err_code = ble_db_discovery_init(&amp;amp;db_init);
    APP_ERROR_CHECK(err_code);
}

static void nus_c_init(void)
{
    ret_code_t       err_code;
    ble_nus_c_init_t init;

    init.evt_handler   = ble_nus_c_evt_handler;
    init.error_handler = nus_error_handler;
    init.p_gatt_queue  = &amp;amp;m_ble_gatt_queue;

    err_code = ble_nus_c_init(&amp;amp;m_ble_nus_c, &amp;amp;init);
    APP_ERROR_CHECK(err_code);
}

static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&amp;amp;init_scan, 0, sizeof(init_scan));

    init_scan.connect_if_match = true;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&amp;amp;m_scan, &amp;amp;init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_scan_filter_set(&amp;amp;m_scan, SCAN_UUID_FILTER, &amp;amp;m_nus_uuid);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_scan_filters_enable(&amp;amp;m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
    APP_ERROR_CHECK(err_code);
}



&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have attached the required functions please take a look.&lt;/p&gt;
&lt;p&gt;1. I am getting other nus_data_handler event (BLE_NUS_EVT_RX_DATA).&lt;/p&gt;
&lt;p&gt;And getting&amp;nbsp;the error&amp;nbsp;sd_ble_gatts_hvx() failed: 0x4 (NRF_ERROR_NO_MEM)&amp;nbsp; when I trying to send data from peripheral to central.&lt;/p&gt;
&lt;p&gt;2. Is fast advertising is causing trouble when the device is trying to scan and connect? because without advertising it&amp;#39;s working.&lt;/p&gt;
&lt;p&gt;3. My requirement is that the device should run with scan and advertise simultaneously. it&amp;#39;s able to connect either as a central or peripheral.&amp;nbsp;And then&amp;nbsp;stop advertisement and scanning when it&amp;#39;s connected. ( I have two nrf52840 boards and need to run the same code in both boards and one should connect as central and the other is peripheral)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble_app_uart peripheral and ble_app_uart central merge.</title><link>https://devzone.nordicsemi.com/thread/299488?ContentTypeID=1</link><pubDate>Fri, 12 Mar 2021 13:37:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67555d32-f13e-4867-bc2b-45759db3fd84</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user=""]1.&amp;nbsp;BLE_NUS_EVT_COMM_STARTED is not triggering when its connected as a peripheral.&amp;nbsp;[/quote]
&lt;p&gt;Have you defined the ble_nus instance in your application using&amp;nbsp;BLE_NUS_DEF? You need a separate instance for both the client and server. If you have not, there will be no instance and BLE events would not be handled by the NUS code. I assume the answer is yes if the NUS code runs as you have been debugging there, but I wont to ask just to be sure. Regarding p_client that is a pointer to client information from the link context manager ()ble_link_ctx_manager). This is used by the NUS implementation but is not something you should need to think about as a user of the NUS service implementation, as it is not part of the API. Perhaps you can elaborate a bit, or show your code?&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;p&gt;2. The device is able to scan and connect without advertising. and when I enable both scan and advertising I am getting errors in the scan event handler when the device trying to scan and connect.&lt;/p&gt;
&lt;p&gt;NRF_BLE_SCAN_EVT_NOT_FOUND and then NRF_BLE_SCAN_EVT_CONNECTING_ERROR and connecting error code is 18.&lt;/p&gt;[/quote]
&lt;p&gt;These are two different errors (either did not find any advertisements matching the filter, or an error occurred while trying to establish a connection). I cannot say anything more without seeing more of your code. I suspect there may be several errors so it is perhaps better to look over the two examples again and ensure you are not missing anything, as that may be just as effective as debugging in this case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>