This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Set UUID in Advertising Data in Peripheral LBS

Hi,

Using the Peripheral LBS sample, is there a way to add advertising data to use both the UUID and name? 

I assume this is to be configured in the bt_data ad declaration and is depended on what _type and expected variables under BT_DATA function however I am not entirely sure whether this is correct. 

The documentation regarding this/examples surrounding this is pretty sparse other than zephyr documentation, but there wasn't much to work with.

Kind regards,

Tyson

Parents
  • Hello Tyson,

    I think it is possible to set UIID and device name of the service as advertising data.  We have an introductory tutorial for Bluetooth Low Energy you can look at GitHub - edvinand/custom_ncs_ble_service_sample.  It shows how to add the device name and the UUID of the service in advertising data- 

    For example in the below code snippet, it shows the device name that is set in the config file, how it is applied in advertising packet inside ad[] and  inside scan response packet sd[] , how randomly generated UUID is added. So when we want to advertise both of these , we can start advertising from bluetooth_init() after the bt_init_ok semaphore has been taken.

    #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
    #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME)-1)
    
    
    static const struct bt_data ad[] = {
        BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
        BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN)
    };
    
    static const struct bt_data sd[] = {
        BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_REMOTE_SERV_VAL),
    };

    int bluetooth_init(struct bt_conn_cb *bt_cb, struct bt_remote_service_cb *remote_cb)
    {
    int err;
    LOG_INF("Initializing Bluetooth");
    
    if (bt_cb == NULL || remote_cb == NULL) {
    return NRFX_ERROR_NULL;
    }
    bt_conn_cb_register(bt_cb);
    remote_service_callbacks.notif_changed = remote_cb->notif_changed;
    remote_service_callbacks.data_received = remote_cb->data_received;
    
    err = bt_enable(bt_ready);
    if (err) {
    LOG_ERR("bt_enable returned %d", err);
    return err;
    }
    
    k_sem_take(&bt_init_ok, K_FOREVER);
    
    err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if (err){
    LOG_ERR("couldn't start advertising (err = %d", err);
    return err;
    }
    
    return err;
    }

    You can look at this tutorial and try to implement similar way in your project. Let us know the outcome.

    Thanks.

    Best Regards,

    Kazi Afroza Sultana

  • Hi Kazi,

    Thank you for the response, simply changing the BT_DATA function calls between the advertising packet and scan response was the solution.

    Cheers,

    Tyson

Reply Children
No Data
Related