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);
}
Parents
  • 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.

Reply
  • 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.

Children
No Data
Related