
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

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
Hi,
Please program the peripheral with https://docs.zephyrproject.org/latest/samples/bluetooth/peripheral_hr/README.html
Regards,
Amanda H.
#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
Hi,
Karthik p said:what's the meaning of error -22 and why this error occurs.
error -22 means Invalid argument returned by bt_conn_le_create.
error -120 for is EALREADY means Socket already connected returned by bt_le_scan_start.
Karthik p said:I am just trying to connect using the MAC id
You can use the function bt_scan_filter_add(..) and provide the scan filter type BT_SCAN_FILTER_TYPE_ADDR along with the address. After scanning, you can match the filter (which can be the MAC ID) using the `scan_filter_match` function. Take a look at the nrf_desktop application and central_nfc_pairing for guidance on how to implement this. Here is the tutorial for scanning and connecting.
-Amanda H.
Hi,
Karthik p said:what's the meaning of error -22 and why this error occurs.
error -22 means Invalid argument returned by bt_conn_le_create.
error -120 for is EALREADY means Socket already connected returned by bt_le_scan_start.
Karthik p said:I am just trying to connect using the MAC id
You can use the function bt_scan_filter_add(..) and provide the scan filter type BT_SCAN_FILTER_TYPE_ADDR along with the address. After scanning, you can match the filter (which can be the MAC ID) using the `scan_filter_match` function. Take a look at the nrf_desktop application and central_nfc_pairing for guidance on how to implement this. Here is the tutorial for scanning and connecting.
-Amanda H.
Thank you