This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to know which Pheripheral typev is connected in BLE_GAP_EVT_CONNECTED event Manage two different peripheral type on one central //

Hello,

I have use the BLE Multi-link Example as a central. For the priripheral I have use BLE Blinky Application and UART/Serial Port Emulation over BLE (<InstallFolder>\examples\ble_peripheral\ble_app_uart).

The need is to have the possibility for the central to manage this two type of peripheral.

First step : define the filter :

#define NUS_SERVICE_UUID_TYPE   BLE_UUID_TYPE_VENDOR_BEGIN              /**< UUID type for the Nordic UART Service (vendor specific). */

/**@brief NUS UUID. */
static ble_uuid_t const m_nus_uuid =
{
    .uuid = BLE_UUID_NUS_SERVICE,
    .type = NUS_SERVICE_UUID_TYPE
};


static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&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(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name);
    APP_ERROR_CHECK(err_code);

    switch (2)
    {
      case (1):
      { // marche pas filtre non effecfif !!
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER | NRF_BLE_SCAN_UUID_FILTER, false);
        APP_ERROR_CHECK(err_code);

        break;
      }

      case (2):
      { 

        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name2);
        APP_ERROR_CHECK(err_code);

        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);

        break;
      }

      default:
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
       break;
    }

}

try one : use two time the  SCAN_NAME_FILTER, the central detecte the advertising of the 2 peripheral and go in ble_evt_handler() event BLE_GAP_EVT_CONNECTED => OK it's working

try two : use  SCAN_NAME_FILTER for BLE blinky and NRF_BLE_SCAN_UUID_FILTER for the "Serial over BLE peripheral" (see code when you put 1 in the case)

in this case, the filter NRF_BLE_SCAN_UUID_FILTER doesn't work and the software doesn't go in the ble_evt_handler() event BLE_GAP_EVT_CONNECTED. Did you have an idea ? the filter seems to be be define correcly?

Question 2 :

When the filter is working using the two SCAN_NAME_FILTER, How can you know in the ble_evt_handler() function event BLE_GAP_EVT_CONNECTED which type of pheripheral generate this event?The information give by the p_gap_evt->params.connected give me not this information.

Thanks in advance

Stephane

  • 1. Are you sure the filter matches the UUID advertised by the peripheral?

    2. I assume you scan for a device first. Then you call sd_ble_gap_connect and provide the address of the device you want to connect to. So at this stage you have already decided which device you should connect to. And you can check this address against the address returned in the BLE_GAP_EVT_CONNECTED event. You can also do a service discovery to see what services the device has. and also check the adv data returned in the connected event.

  • Hi,

    Question 1. I use what is define by nordic :

    For peripheral, in  BLE_NUS.C (line 64) :

    #define NUS_BASE_UUID                  {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}} /**< Used vendor specific UUID. */

    For Central, in ble_nus_c.h (line 101)

    #define NUS_BASE_UUID                   {{0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}} /**< Used vendor specific UUID. */

    A other idea ?

    Question 2 :

    No I don't scan for a device first. One type of device or the other could be power supply first!!

    if I use the sd_ble_gap_connect() fonction to scan :

    - this fonction is not call today in the main

    - I have to replace the  scan_start() with this function ?

    - you speak about the 'addresse of the device' : How can I know the address?

    In the ble_evt_handler() called with the event BLE_GAP_EVT_CONNECTED, the only information to know the device is also the peer_addr.addr ?

    Thanks in advance

    Stephane

  • 1. Have you done any pairing or similar? any chance you could have a whitelist?

    2. I would recommend scanning first, then connect. Regardless you should check the information in the struct returned by the connected event. And the struct returned by the scan function ble_gap_evt_adv_t to see what options you have to identify the devices.

Related