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

Connecting to Pi/Bleno with sd_ble_gap_connect

Hi,

I'm trying to connect to a Raspberry Pi from an nRF52832 via BLE Central mode. The Pi is running a node.js app (via bleno) and I can connect and communicate with it just fine using the nRF Connect app.

I can use sd_ble_gap_scan_start and can see the device advertising itself, however when I use sd_ble_gap_connect to connect using its mac address, nothing happens (it just times out).

I can connect fine to other nRF52832-based devices though.

I'm using:

  static ble_gap_scan_params_t     m_scan_param;
  memset(&m_scan_param, 0, sizeof(m_scan_param));
  m_scan_param.active       = 0;            // Active scanning set.
  m_scan_param.interval     = MSEC_TO_UNITS(100, UNIT_0_625_MS); // Scan interval.
  m_scan_param.window       = MSEC_TO_UNITS(100, UNIT_0_625_MS); // Scan window.
  m_scan_param.timeout      = 4;            // 4 second timeout.

  static ble_gap_conn_params_t   gap_conn_params;
  memset(&gap_conn_params, 0, sizeof(gap_conn_params));
  gap_conn_params.min_conn_interval = MSEC_TO_UNITS(7.5, UNIT_1_25_MS);
  gap_conn_params.max_conn_interval = MSEC_TO_UNITS(75, UNIT_1_25_MS);
  gap_conn_params.slave_latency     = 0;
  gap_conn_params.conn_sup_timeout  = MSEC_TO_UNITS(4000, UNIT_10_MS);

  err_code = sd_ble_gap_connect(&addr, &m_scan_param, &gap_conn_params);

The only obvious difference I can find is the Pi comes up in nRF connect as GeneralDiscoverable whereas other nRF devices are LimitedDiscoverable.

Any thoughts? A longer (or no) timeout doesn't help matters.

Also, I was occasionally getting NRF_ERROR_INVALID_PARAM before I made the arguments static, but I'm not getting it after. Is that a red herring? I'd prefer not to make things static if it's not required.

Related