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);
}
  • Yes, I'm getting ad reports from peripheral device I want to connect to. (If there is no other peripheral device in the environment!)

  • So you are actually able to connect? Are you sure you are connecting to the peripheral you want to send commands to? How do you know? How does the central know which peripheral to connect to? (If all are advertising with the same UUID and this is what the central uses to filter what devices to connect to) You can use a whitelist to filter all advertisements that are not in the whitelist, but then you must put in the address of the device that you want to accept advertisements from.

    The button is used to start scanning and connection? What happens the second time it is pressed? Disconnection and then start scanning and new connection?

  • I can connect to one of the peripheral devices, but I do not know which one. That's why I can not send command . I used app_trace_log and I can see the device is connected in log datas(connect the device with uart). The central device is looking for uuid, but uuid is not a distinguishing feature. Because all peripheral devices use the same service uuid. I want to register the peer address of the peripheral device to the central device after I first make a healthy connection and send the command. Then I need to call the peer address instead of uuid to connect to the peripheral device.

  • Hi
    Petter is unavailable, and I will try to follow this up in the mean time.
    Do you think it is possible to attach your code, so we can have a look at it?
    Then it is easier for us to understand how your code is working, and what the problem might be.
    If so, please just zip your project, and attach the zip file to this case (you can't really attach a file to a comment, so just update you initial inquiry).
    Best regards

Related