Zephyr bt_adv Too big advertising data

I would like to add NUS, BAS, and SMP services to advertisement. But the following error messages shown on RTT Viewer.

00> *** Booting Zephyr OS build v3.2.99-ncs2 ***
00> [00:00:00.001,617] <inf> main: button long press test
00>
00> Starting button Test example
00> btInit() e
00> bt_passkey_set(123456)
00> btInit() x
00> _btReady(0) e
00> Bluetooth initialized
00> [00:00:00.032,745] <err> bt_adv: Too big advertising data
00> Advertising failed to start (err 0xffffffea)
00> _btReady(0) x

The following are source code.

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, 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
                                       0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
    BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
    BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)),
};

int btAdvStart(void) {
    int ret = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
    if (ret != 0) {
        printk("Advertising failed to start (err 0x%x)\n", ret);
        return ERROR_ADVERTISING_START_FAIL;
    }
    
    return 0;
}

  • #include <bluetooth/services/nus.h>
    #include <zephyr/bluetooth/bluetooth.h>
    #include <zephyr/bluetooth/conn.h>
    #include <zephyr/bluetooth/uuid.h>
    #include <zephyr/bluetooth/gatt.h>
    #include <zephyr/kernel.h>
    #include <zephyr/sys/printk.h>
    #include "error.h"
    
    #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, 0x84, 0xaa, 0x60, 0x74, 0x52, 0x8a, 0x8b, 0x86,
                                           0xd3, 0x4c, 0xb7, 0x1d, 0x1d, 0xdc, 0x53, 0x8d),
        BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
        BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(BT_UUID_BAS_VAL)),
    };
    
    int btAdvStart(void) {
        int ret = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
        if (ret != 0) {
            printk("Advertising failed to start (err 0x%x)\n", ret);
            return ERROR_ADVERTISING_START_FAIL;
        }
        
        return 0;
    }
    
    

  • Hi, 
    The error means what it means "Too big advertising data"

    You don't have enough space in the scan response data (sd) for two 128 bit UUID and one 16 bit UUID. The maximum length of an advertising packet or a scan response packet is 31 bytes. This is included all the flags and headers. 

    My suggestion is to go through out Bluetooth Nordic Academy : https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/

    Advertising is covered in Chapter 2. 

  • Thanks for your reply! Is SMP service advertising mandatory for Over-the-air (OTA) update? I would like to remove SMP service from advertising packet if it isn't mandatory for OTA update.

  • Hi, 

    Not really. It's used so that the app on the phone can be easier to detect if there OTA is supported on the device or not. But it's not mandatory. You can make the app that simply connect to your device, do the service discovery and can detect that if OTA is supported or not. 

    You can see that nRF Connect app can do that. 

  • Thanks for your reply! I will remove SMP service from advertising packets.

Related