Error(-22) on connecting to the peripheral using nrf52840 as central

Hi 

this is the error when I tried to connect to peripheral and also get the error on scanning after that connection error 

I am using the sample code for this application https://docs.zephyrproject.org/latest/samples/bluetooth/central_hr/README.html

Parents
  • #include <zephyr/kernel.h>
    #include <zephyr/bluetooth/bluetooth.h>
    #include <zephyr/bluetooth/conn.h>
    #include <zephyr/bluetooth/gatt.h>
    #include <bluetooth/scan.h> 
    
    static struct bt_conn *default_conn;  // Use a more descriptive name
    
    static void device_found(const bt_addr_le_t *addr, int8_t rssi,
                              uint8_t adv_type, struct net_buf_simple *buf) {
        int err;
        char addr_str[BT_ADDR_LE_STR_LEN];
    
        bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
        printk("Device found: %s (RSSI %d)\n", addr_str, rssi);
    
        // Handle connection logic (consider adding filtering or selection)
        if(!strcmp(addr_str,"00:18:80:00:BD:02 (public)")){
        err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
                                BT_LE_CONN_PARAM_DEFAULT, &default_conn);
        if (err) {
            printk("Error connecting: %d\n", err);
        } else {
            // Successfully connected, handle connection established event
            printk("Connected to: %s\n", addr_str);
            bt_scan_stop();
            return;
            // (Add further actions for the connected device here)
        }
        }
    }
    
    static void scan_start(void) {
        int err;
    
        err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
        if (err) {
            printk("Error starting scan: %d\n", err);
        }
    }
    
    void main(void) {
        int err;
    
        err = bt_enable(NULL);
        if (err) {
            printk("Error enabling Bluetooth: %d\n", err);
            return;
        }
    
        scan_start();
    
        // Add a loop or blocking call to keep the program running
        while (1) {
            k_sleep(K_MSEC(1000));  // Sleep for 1 second
        }
    }

    this is the code I am running here I my not discovering the service 

    I am just trying to connect using the MAC id 

    BR 

    Karthik P 

Reply
  • #include <zephyr/kernel.h>
    #include <zephyr/bluetooth/bluetooth.h>
    #include <zephyr/bluetooth/conn.h>
    #include <zephyr/bluetooth/gatt.h>
    #include <bluetooth/scan.h> 
    
    static struct bt_conn *default_conn;  // Use a more descriptive name
    
    static void device_found(const bt_addr_le_t *addr, int8_t rssi,
                              uint8_t adv_type, struct net_buf_simple *buf) {
        int err;
        char addr_str[BT_ADDR_LE_STR_LEN];
    
        bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
        printk("Device found: %s (RSSI %d)\n", addr_str, rssi);
    
        // Handle connection logic (consider adding filtering or selection)
        if(!strcmp(addr_str,"00:18:80:00:BD:02 (public)")){
        err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN,
                                BT_LE_CONN_PARAM_DEFAULT, &default_conn);
        if (err) {
            printk("Error connecting: %d\n", err);
        } else {
            // Successfully connected, handle connection established event
            printk("Connected to: %s\n", addr_str);
            bt_scan_stop();
            return;
            // (Add further actions for the connected device here)
        }
        }
    }
    
    static void scan_start(void) {
        int err;
    
        err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
        if (err) {
            printk("Error starting scan: %d\n", err);
        }
    }
    
    void main(void) {
        int err;
    
        err = bt_enable(NULL);
        if (err) {
            printk("Error enabling Bluetooth: %d\n", err);
            return;
        }
    
        scan_start();
    
        // Add a loop or blocking call to keep the program running
        while (1) {
            k_sleep(K_MSEC(1000));  // Sleep for 1 second
        }
    }

    this is the code I am running here I my not discovering the service 

    I am just trying to connect using the MAC id 

    BR 

    Karthik P 

Children
Related