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

How to create a whitelist on the Central device

I want to create a whitelist on the Central device. Because there is a lot of peripheral devices around and I just want to connect one peripheral device. First I register the address of the central device to the peripheral device. When I work with a single peripheral device and a single central device, I can send commands from the central device to the peripheral device. But when I have more than one peripheral device in the vicinity, I can not send commands to the peripheral device registered from the central device. So I decided to create whitelist on the central device to connect the peripheral device which I registered before. But I don't know how. Do you have any example? (except ble_app_hrs)

Function to start scanning code;

// Function to start scanning
void scan_start(void) {
  ble_gap_whitelist_t   whitelist;
  ble_gap_addr_t      * p_whitelist_addr[BLE_GAP_WHITELIST_ADDR_MAX_COUNT];
  ble_gap_irk_t       * p_whitelist_irk[BLE_GAP_WHITELIST_IRK_MAX_COUNT];
  uint32_t              err_code;
  uint32_t              count;    

  err_code = pstorage_access_status_get(&count);
  APP_ERROR_CHECK(err_code);

  if (count != 0)
  {
      m_memory_access_in_progress = true;
      return;
  }
	
  // Initialize whitelist parameters.
  whitelist.addr_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
  whitelist.irk_count  = 0;
  whitelist.pp_addrs   = p_whitelist_addr;
  whitelist.pp_irks    = p_whitelist_irk;

  // Request creating of whitelist.
  err_code = dm_whitelist_create(&m_dm_app_id,&whitelist);
  APP_ERROR_CHECK(err_code);
	
  if (((whitelist.addr_count == 0) && (whitelist.irk_count == 0)) ||
      (m_scan_mode != BLE_WHITELIST_SCAN)                        ||
      (m_whitelist_temporarily_disabled))
  {
      APPL_LOG("THERE IS NO WHITELIST\r\n");		//Debug Note
      // No devices in whitelist, hence non selective performed.
      m_scan_param.active       = SCAN_ACTIVE;        // Active scanning set.
      m_scan_param.selective    = SCAN_SELECTIVE;     // Selective scanning not set.
      m_scan_param.interval     = SCAN_INTERVAL;			// Scan interval.
      m_scan_param.window       = SCAN_WINDOW;  			// Scan window.
      m_scan_param.p_whitelist  = NULL;        				// No whitelist provided.
      m_scan_param.timeout      = 0x0000;       			// No timeout.
			
  }
  else
  {
      APPL_LOG("WHITELIST WAS FOUND\r\n");		//Debug Note
      // Selective scanning based on whitelist first.
      m_scan_param.active       = 1;            // Active scanning set.
      m_scan_param.selective    = 1;            // Selective scanning not set.
      m_scan_param.interval     = SCAN_INTERVAL;// Scan interval.
      m_scan_param.window       = SCAN_WINDOW;  // Scan window.
      m_scan_param.p_whitelist  = &whitelist;   // Provide whitelist.
      m_scan_param.timeout      = 0x001E;       // 30 seconds timeout.
		
      m_scan_mode = BLE_WHITELIST_SCAN;
  }

  err_code = sd_ble_gap_scan_start(&m_scan_param);
  APP_ERROR_CHECK(err_code);
}
  • Which SDK are you using? Which peripheral and central examples are you using? What do you mean by register the address of the central device to the peripheral device?

    You say you are not able to send commands, but are you able to connect to the correct device?

    If you know the address of the peripheral device you want to connect to you can simply call sd_ble_gap_connect() with the specific device address. The SoftDevice will then look for that address and connect to it, and it will ignore advertisments from all other addresses.

    • Peripheral device use SDK 8.0 Softdevice S110
    • Central device use SDK10.0 Softdevice S130
    • I do not use sdk examples.
    • I am recording the peer address of the central device to the peripheral device. Because I just want only registered central device can send commands to the peripheral device.
    • If there are more than one peripheral device I can not connect and send command to the correct device.
    • I dont know address but I know ServicesCompleteListUuid. And If peripheral device advertise with this Uuid Central device can register itself.
  • Any idea why you can't connect? Are you connecting to another peripheral? What is happening on your central? Are you getting advertising reports from the peripheral you want to connect to at all?

    If you want a whitelist on the central you need the peripherals device address. It will be in the advertising reports or you can extract it from an earlier connection event.

  • According to Mr.Ulrich Myhre : If there is a lot of advertisers around, all advertising extremely fast, they might end up transmitting exactly at the same time as a connect request is being sent to another device. That will corrupt the request

    • In my opinion some signal confusion happened as Mr.Ulrich Myhre said.
    • I can not connect another peripheral
    • Central starts scanning and try to connect untill timeout.
    • If there are multiple peripheral devices around, I can not get advertising reports from peripheral. Because the central device can only scanning, it can not do anything else. If there are not many peripheral devices around, it working smoothly.

    So, If I can extract advertising report from earlier connection event and create whitelist as you said, I think All problem will be solved.

Related