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

nrf52832 zephyr central device cannot reconnect to a peripheral

I have an nrf52832 acting as a central device that is trying to connect to a peripheral. However, after the peripheral disconnects and the central tries to reconnect I get an error with value -22.  Here is the pseudo code.

static bt_conn* conn = NULL;

static void connect() {
  //err has a value of -22
  int err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
  BT_LE_CONN_PARAM_DEFAULT, &conn);

  if (err) {
    printk("Error %d\n, err);
  }
}

static void on_disconnect(...) {

  bt_conn_unref(conn);
  conn = NULL;

}

So the first time connect() is called there is no error.  When the peripheral disconnects, the conn pointer is unreferenced and then set to NULL again.  The second time connect() is called bt_conn_le_create returns -22, which is -EINVAL or invalid argument but correct me if I am wrong.  Any insight would be helpful.  Thanks,

 

Related