Skip to content

Commit 3d65a8e

Browse files
author
Stefan Jaritz
committed
samples: bluetooth: fix periphal hr restart advertising
fix: - at ext. adv we don't need to rebuild the adv payload Signed-off-by: Stefan Jaritz <stefan.jaritz@gmail.com>
1 parent 1eed2fa commit 3d65a8e

File tree

1 file changed

+38
-42
lines changed
  • samples/bluetooth/peripheral_hr/src

1 file changed

+38
-42
lines changed

samples/bluetooth/peripheral_hr/src/main.c

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,42 @@ static void blink_stop(void)
198198
static int start_adv(void)
199199
{
200200
int err;
201+
#if !defined(CONFIG_BT_EXT_ADV)
202+
printk("Starting Legacy Advertising (connectable and scannable)\n");
203+
err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
204+
if (err) {
205+
printk("Advertising failed to start (err %d)\n", err);
206+
return 0;
207+
}
208+
209+
#else /* CONFIG_BT_EXT_ADV */
210+
printk("Starting Extended Advertising (connectable and non-scannable)\n");
211+
err = bt_le_ext_adv_start(ad, BT_LE_EXT_ADV_START_DEFAULT);
212+
if (err) {
213+
printk("Failed to start extended advertising set (err %d)\n", err);
214+
return 0;
215+
}
216+
#endif /* CONFIG_BT_EXT_ADV */
217+
218+
return 0;
219+
}
220+
221+
int main(void)
222+
{
223+
int err;
224+
225+
err = bt_enable(NULL);
226+
if (err) {
227+
printk("Bluetooth init failed (err %d)\n", err);
228+
return 0;
229+
}
230+
231+
printk("Bluetooth initialized\n");
232+
233+
bt_conn_auth_cb_register(&auth_cb_display);
234+
235+
bt_hrs_cb_register(&hrs_cb);
236+
201237
#if !defined(CONFIG_BT_EXT_ADV)
202238
printk("Starting Legacy Advertising (connectable and scannable)\n");
203239
err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
@@ -246,31 +282,8 @@ static int start_adv(void)
246282
return err;
247283
}
248284
#endif /* CONFIG_BT_EXT_ADV */
249-
return 0;
250-
}
251285

252-
int main(void)
253-
{
254-
int err;
255-
256-
err = bt_enable(NULL);
257-
if (err) {
258-
printk("Bluetooth init failed (err %d)\n", err);
259-
return 0;
260-
}
261-
262-
printk("Bluetooth initialized\n");
263-
264-
bt_conn_auth_cb_register(&auth_cb_display);
265-
266-
bt_hrs_cb_register(&hrs_cb);
267-
268-
err = start_adv();
269-
if (0 == err) {
270-
printk("Advertising successfully started\n");
271-
} else {
272-
printk("Advertising failed to start\n");
273-
}
286+
printk("Advertising successfully started\n");
274287

275288
#if defined(HAS_LED)
276289
err = blink_setup();
@@ -298,24 +311,7 @@ int main(void)
298311
blink_stop();
299312
#endif /* HAS_LED */
300313
} else if (atomic_test_and_clear_bit(state, STATE_DISCONNECTED)) {
301-
#if !defined(CONFIG_BT_EXT_ADV)
302-
printk("Starting Legacy Advertising (connectable and scannable)\n");
303-
err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, ARRAY_SIZE(ad), sd,
304-
ARRAY_SIZE(sd));
305-
if (err) {
306-
printk("Advertising failed to start (err %d)\n", err);
307-
return 0;
308-
}
309-
310-
#else /* CONFIG_BT_EXT_ADV */
311-
printk("Starting Extended Advertising (connectable and non-scannable)\n");
312-
err = bt_le_ext_adv_start(adv, BT_LE_EXT_ADV_START_DEFAULT);
313-
if (err) {
314-
printk("Failed to start extended advertising set (err %d)\n", err);
315-
return 0;
316-
}
317-
#endif /* CONFIG_BT_EXT_ADV */
318-
314+
start_adv();
319315
#if defined(HAS_LED)
320316
blink_start();
321317
#endif /* HAS_LED */

0 commit comments

Comments
 (0)