This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

AN36 modifications

I want to add to lbs service battery service(bas) as well. One of the changes is in the advertising_init() function:


static void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
    ble_uuid_t adv_uuids[] = 
    {
        {BLE_UUID_BATTERY_SERVICE, m_lbs.uuid_type},
        {LBS_UUID_SERVICE, m_lbs.uuid_type}
    };

    // Build and set advertising data
    memset(&advdata, 0, sizeof(advdata));
    
    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags.size              = sizeof(flags);
    advdata.flags.p_data            = &flags;
    advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = adv_uuids;
    
    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);
}

As a result I have NRF_ERROR_DATA_SIZE I did use blood pressure service as an example. What did I miss?

Thank you.

  • If you want to advertise a regular Bluetooth SIG service like the battery service, you should use BLE_UUID_TYPE_BLE and not m_lbs.uuid_type. Using the latter will set the Battery Service's 16-bit UUID on top of the Led Button service's base UUID, which is not what you want.

    The error 0x0C shows that your advertisement packet is too big. For details, take a look at this and this question, and also section 4.4.6 of the application note.

  • Thank you for the reply. I do not understand what this exactly means:> I dropped the other services and pared the name down.

    Also, I'm aware of size limitations but how does ble_advdata_t is converted into the message, so I can count it's size? Sorry I didn't find this in ble_advdata.h. How to split correctly long message between the advertisement package and the scan response. Could you please point me to an example.

    Thank you.

  • I assume the user who wrote that means that he removed some of the services and then shortened his name.

    There isn't any magic way to know how large the packet is, but if you look at the source code for ble_advdata, you can see the raw packet as passed to sd_ble_advdata_set(). This is the size of advertising data as seen on air. You can also take a look at the Core Specification, Volume 3, Part C, chapter 11, which details the different fields available.

    There isn't any right or wrong way to separate data between the advertisement packet and scan response, you are more or less free to choose as you see fit. The only exception I'm aware of is that you are allowed to have the name only one place, and that the Flags field shall be in the advertisement. You may also want to consider Apple's recommendations in section 3.4 of their Bluetooth Accessory Design Guidelines, if that is a target platform of yours: https://developer.apple.com/hardwaredrivers/bluetoothdesignguidelines.pdf

  • I'm assuming that > the source code for ble_advdata you mean file ble_advdata.c but in any case I do not see sd_ble_advdata_set(): not in this file nor anywhere else. Also there is a function sd_ble_gap_appearance_get(). Should it not return what sd_ble_gap_appearance_set() sets? Template uses

    
        /* YOUR_JOB: Use an appearance value matching the application's use case.
        err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_);
        APP_ERROR_CHECK(err_code); */
    
    

    AN36 doesn't have this snippet or I missed it but somehow appearance gets initialized to 0x1234 and the code is not for debugging... I'm sorry for the next question because I'm sure BLE Core v.4 has the answer but having advertisement package and the scan response limits is limiting to less than 62 bytes. What am I missing? Or if it is necessary one can modify ads by changing my advertisement data?

    Thanks.

  • Sorry, the method name was a typo from my part, it is sd_ble_gap_adv_data_set(), which as you can see is the final call of ble_advdata_set().

    It seems that current softdevices will initialize the appearance to 0x1234, but this will most likely be changed in future versions to just 0. If you want to, you can set appearance to one of the values from this list: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml

    As for the latter part of your question, I'm not sure I understand it. With the S110, you can change the advertising data at any time, by either calling sd_ble_gap_adv_data_set() or ble_advdata_set(). You can however not advertise more than 31 bytes in the advertisement packet and 31 bytes in the scan response, and all data must be part of some advertising type as defined in the specification.

Related