How do I filter and connect to BLE devices using the device name in Zephyr?
How do I filter and connect to BLE devices using the device name in Zephyr?
I added the device name to the advertising data as bellow:
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
struct bt_conn *default_conn;
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, DEVICE_NAME),
BT_DATA_BYTES(BT_DATA_UUID128_ALL,
0xef, 0x41, 0x16, 0xdf, 0x0a, 0x11, 0x4b, 0x49,
0xae, 0x5a, 0x65, 0x92, 0xd5, 0xa2, 0x6d, 0xa5),
};
I then get the following error in the serial terminal
Advertising failed to start (err -22)
Where can I look up the error code?
Hi!
-22 means invalid argument. You can look up the error codes in libc minimal errno.h or newlib errno.h depending on if your application is built with newlib library or not (CONFIG_NEWLIB_LIBC is enabled).
You have to add it using the BT_DATA macro like this:
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LENGTH)
Hi!
I have tried the suggested BT_DATA macro and I am still getting the same error. I even tried to add it to the scan response data with no success.
static const struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
//BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME,DEVICE_NAME_LEN),
BT_DATA_BYTES(BT_DATA_UUID128_ALL,
0xef, 0x41, 0x16, 0xdf, 0x0a, 0x11, 0x4b, 0x49,
0xae, 0x5a, 0x65, 0x92, 0xd5, 0xa2, 0x6d, 0xa5),
};
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
I am not sure if there is something specific I need to add to the config file to enable this?
That's a bit strange. How are you defining DEVICE_NAME_LEN?
Hi I am defining it as below:
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)