Browse Source

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>
pull/90645/head
Nirav Agrawal 2 months ago committed by Benjamin Cabé
parent
commit
767772aad1
  1. 26
      samples/bluetooth/bthome_sensor_template/src/main.c

26
samples/bluetooth/bthome_sensor_template/src/main.c

@ -34,11 +34,18 @@ static struct bt_data ad[] = { @@ -34,11 +34,18 @@ static struct bt_data ad[] = {
BT_DATA(BT_DATA_SVC_DATA16, service_data, ARRAY_SIZE(service_data))
};
static void bt_ready(int err)
int main(void)
{
int err;
int temp = 0;
printk("Starting BTHome sensor template\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(NULL);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
return 0;
}
printk("Bluetooth initialized\n");
@ -47,21 +54,6 @@ static void bt_ready(int err) @@ -47,21 +54,6 @@ static void bt_ready(int err)
err = bt_le_adv_start(ADV_PARAM, ad, ARRAY_SIZE(ad), NULL, 0);
if (err) {
printk("Advertising failed to start (err %d)\n", err);
return;
}
}
int main(void)
{
int err;
int temp = 0;
printk("Starting BTHome sensor template\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(bt_ready);
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return 0;
}

Loading…
Cancel
Save