Skip to content

Commit 767772a

Browse files
nirav-agrawalkartben
authored andcommitted
samples: bluetooth: fix adv_update error in bthome_sensor_template
- "bt_le_adv_update_data()" func calls just after bt_enable() call without completion of bt_ready() which is called as part of worker thread within init_work() causes issue where bluetooth controller has not been initialized and provides cb to app before app requests advertise_update to the stack. - remove bt_ready() func and place content within main() post bt_enable() fixes this issue. Signed-off-by: Nirav Agrawal <nirav.agrawal@nxp.com>
1 parent 46cf96a commit 767772a

File tree

1 file changed

+9
-17
lines changed
  • samples/bluetooth/bthome_sensor_template/src

1 file changed

+9
-17
lines changed

samples/bluetooth/bthome_sensor_template/src/main.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ static struct bt_data ad[] = {
3434
BT_DATA(BT_DATA_SVC_DATA16, service_data, ARRAY_SIZE(service_data))
3535
};
3636

37-
static void bt_ready(int err)
37+
int main(void)
3838
{
39+
int err;
40+
int temp = 0;
41+
42+
printk("Starting BTHome sensor template\n");
43+
44+
/* Initialize the Bluetooth Subsystem */
45+
err = bt_enable(NULL);
3946
if (err) {
4047
printk("Bluetooth init failed (err %d)\n", err);
41-
return;
48+
return 0;
4249
}
4350

4451
printk("Bluetooth initialized\n");
@@ -47,21 +54,6 @@ static void bt_ready(int err)
4754
err = bt_le_adv_start(ADV_PARAM, ad, ARRAY_SIZE(ad), NULL, 0);
4855
if (err) {
4956
printk("Advertising failed to start (err %d)\n", err);
50-
return;
51-
}
52-
}
53-
54-
int main(void)
55-
{
56-
int err;
57-
int temp = 0;
58-
59-
printk("Starting BTHome sensor template\n");
60-
61-
/* Initialize the Bluetooth Subsystem */
62-
err = bt_enable(bt_ready);
63-
if (err) {
64-
printk("Bluetooth init failed (err %d)\n", err);
6557
return 0;
6658
}
6759

0 commit comments

Comments
 (0)