Bluetooth: Samples: Dev name in AD instead of SD

With the deprecation of `BT_LE_ADV_OPT_USE_NAME` and
`BT_LE_ADV_OPT_FORCE_NAME_IN_AD` samples were updated to not use the
macro adding the device name in the advertising/scan response data
anymore.

Instead the name was explicitly added to the scan response data in
`periodic_adv` sample. But because it was using an extended advertiser
and was already adding data in the AD, the name should have been put in
the advertising data and not the scan response data.

Update the sample to add the device name in the advertising data.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
This commit is contained in:
Théo Battrel 2024-04-24 06:57:55 +02:00 committed by Carles Cufí
parent 27e8bc65c7
commit 8f7df0b49f

View file

@ -8,11 +8,11 @@
static uint8_t mfg_data[] = { 0xff, 0xff, 0x00 }; static uint8_t mfg_data[] = { 0xff, 0xff, 0x00 };
static const struct bt_data ad[] = { static const struct bt_data per_adv_ad[] = {
BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3), BT_DATA(BT_DATA_MANUFACTURER_DATA, mfg_data, 3),
}; };
static const struct bt_data sd[] = { static const struct bt_data ad[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
}; };
@ -38,7 +38,7 @@ int main(void)
} }
/* Set advertising data to have complete local name set */ /* Set advertising data to have complete local name set */
err = bt_le_ext_adv_set_data(adv, NULL, 0, sd, ARRAY_SIZE(sd)); err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) { if (err) {
printk("Failed to set advertising data (err %d)\n", err); printk("Failed to set advertising data (err %d)\n", err);
return 0; return 0;
@ -75,7 +75,7 @@ int main(void)
mfg_data[2]++; mfg_data[2]++;
printk("Set Periodic Advertising Data..."); printk("Set Periodic Advertising Data...");
err = bt_le_per_adv_set_data(adv, ad, ARRAY_SIZE(ad)); err = bt_le_per_adv_set_data(adv, per_adv_ad, ARRAY_SIZE(per_adv_ad));
if (err) { if (err) {
printk("Failed (err %d)\n", err); printk("Failed (err %d)\n", err);
return 0; return 0;