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);
}
  • How to store peer address of peripheral into central ? After that, how to add peer address into whitelist ?

    NOTE: I can store Central peer address into the peripheral because Peripheral can advertise and I can save peer address via pstorage register. But central device just scanning that's why I couldn't do that. I hope I could tell the problem.

  • If you want store the peripherals address persistently you can use Pstorage or Fstorage.

    I have already told you how to add the peripheral address to the whitelist.

    Have you tried? What is the problem?

  • I noticed something interesting. I started all over again. I placed many peripheral devices around the central device, I pressed the button and the central device could not send commands again. Then I got angry and pressed the button many times. Then guess what? Central device sent command and peripheral device which I want took command. Then I tried this scenario many times. And Same thing happened.

    I summarize the result from this activity;

    • If many peripheral devices around the central device, you should to press the button many times
    • If there is only one peripheral around the central device, you just press the button once.

    So, Do you have any idea about the problem?

  • Again, you need to include more code and explanation if I'm going to understand what you are doing/what is happening.

    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? What exactly does this button do?

  • Ok. Mr Myhre. I'm sorry that I can not express well. I will try to answer your questions;

    If there is one peripheral and one central device, I can connect and send commands. But If there are other peripheral devices that broadcast with the same uuid around the Central device, I can not send commands even when I connect. When this happens, the central device behaves irrationally.When I am eliminating other peripheral devices from the environment (only one peripheral remains), the central device is working smoothly again. What I think I can not express here is that the central device must first register the peer address to the peripheral device in order to send the command. If the peer address of the central device is not registered in the peripheral, it can not send commands even when connected.

    The button is used to initiate the event.(Start scanning, connection etc.)

Related