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>
This commit is contained in:
Nirav Agrawal 2025-05-20 20:42:37 +05:30 committed by Benjamin Cabé
commit 767772aad1

View file

@ -34,23 +34,6 @@ static struct bt_data ad[] = {
BT_DATA(BT_DATA_SVC_DATA16, service_data, ARRAY_SIZE(service_data)) BT_DATA(BT_DATA_SVC_DATA16, service_data, ARRAY_SIZE(service_data))
}; };
static void bt_ready(int err)
{
if (err) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
/* Start advertising */
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 main(void)
{ {
int err; int err;
@ -59,12 +42,21 @@ int main(void)
printk("Starting BTHome sensor template\n"); printk("Starting BTHome sensor template\n");
/* Initialize the Bluetooth Subsystem */ /* Initialize the Bluetooth Subsystem */
err = bt_enable(bt_ready); err = bt_enable(NULL);
if (err) { if (err) {
printk("Bluetooth init failed (err %d)\n", err); printk("Bluetooth init failed (err %d)\n", err);
return 0; return 0;
} }
printk("Bluetooth initialized\n");
/* Start advertising */
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 0;
}
for (;;) { for (;;) {
/* Simulate temperature from 0C to 25C */ /* Simulate temperature from 0C to 25C */
service_data[IDX_TEMPH] = (temp * 100) >> 8; service_data[IDX_TEMPH] = (temp * 100) >> 8;