Problem encoding and advertising the BT_UUID_NUS_VAL

Hi. I am working on a project trying to encode the BT_UUID_NUS_VAL into advertising packets without success. 

In am using the unicast_server.c file as a reference. There there is the following : 

static uint8_t unicast_server_adv_data[] = {
	BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL),
	BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED,
	BT_BYTES_LIST_LE16(AVAILABLE_SINK_CONTEXT),
	BT_BYTES_LIST_LE16(AVAILABLE_SOURCE_CONTEXT),
	0x00, /* Metadata length */
};

This advertises fine as expected. However, instead of advertising BT_UUID_ASCS_VAL which has a simple value of 0x1853, I would like to advertise BT_UUID_NUS_VAL. The problem is that this has a large value of 6e400001-b5a3-f393-e0a9-e50e24dcca9e. 

I tried the following without success :  

static uint8_t unicast_server_adv_data[] = {
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
	BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED,
	BT_BYTES_LIST_LE16(AVAILABLE_SINK_CONTEXT),
	BT_BYTES_LIST_LE16(AVAILABLE_SOURCE_CONTEXT),
	0x00, /* Metadata length */
};

How could I go about possibly solving this? Thank you in advance.

  • Hi

    I don't think you should use the unicast file (related to LE audio), to do standard BLE advertising. I'd strongly suggest checking out how advertising the Nordic UART service is done in the peripheral_uart sample, that does just this already. I'd also recommend the Nordic DevAcademy and the Bluetooth Low Energy fundamentals course that explains how to do BLE advertising in detail.

    Best regards,

    Simon

  •    Thanks for your reply.

    The peripheral_uart sample uses bt_le_adv_start() to start the advertising. I can't use this in my case due to previous issues.

    I must initialize advertising with bt_mgmt_adv_start() and eventually bt_le_ext_adv_start() gets called. I must use a structure similar to that of unicast_server_adv_data

    So is there no way to advertise the BT_UUID_NUS_VAL this way you mean? Only using the legacy bt_le_adv_start() . 

    I've taken the BLE fundamentals course already. Thanks. 

  • Hi

    What issues exactly did you have with bt_le_adv_start()? You need to make sure that the mgmt_adv_start() has room for 128 bits for the UUID. What errors are you running into exactly when trying to use bt_mgmt_adv_start() to advertise with the NUS UUID?

    Best regards,

    Simon

  •  Hi  

    When I try to create the advertising data as follows, for mgmt_adv_start() : 

    static uint8_t unicast_server_adv_data[] = {
    	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
    	BT_AUDIO_UNICAST_ANNOUNCEMENT_TARGETED,
    	BT_BYTES_LIST_LE16(AVAILABLE_SINK_CONTEXT),
    	BT_BYTES_LIST_LE16(AVAILABLE_SOURCE_CONTEXT),
    	0x00, /* Metadata length */
    };

    I get all sorts of issues : 

    warning: braces around scalar initializer
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: (near initialization for 'adv_data[0]')
    In file included from C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/conn.h:23,
                     from C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/hci.h:16,
                     from C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/buf.h:24,
                     from C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/audio/audio.h:22,
                     from ../../../src/bluetooth/le_audio.h:10,
                     from ../../../src/bluetooth/bt_stream/broadcast/broadcast_sink.h:10,
                     from ../../../src/audio/streamctrl_broadcast_sink.c:13:
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:451:17: error: field name not in record or union initializer
      451 |                 .type = (_type), \
          |                 ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:451:17: note: (near initialization for 'adv_data[0]')
      451 |                 .type = (_type), \
          |                 ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:452:17: error: field name not in record or union initializer
      452 |                 .data_len = (_data_len), \
          |                 ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:452:17: note: (near initialization for 'adv_data[0]')
      452 |                 .data_len = (_data_len), \
          |                 ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:452:29: warning: excess elements in scalar initializer
      452 |                 .data_len = (_data_len), \
          |                             ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:452:29: note: (near initialization for 'adv_data[0]')
      452 |                 .data_len = (_data_len), \
          |                             ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:453:17: error: field name not in record or union initializer
      453 |                 .data = (const uint8_t *)(_data), \
          |                 ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:453:17: note: (near initialization for 'adv_data[0]')
      453 |                 .data = (const uint8_t *)(_data), \
          |                 ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:453:25: warning: excess elements in scalar initializer
      453 |                 .data = (const uint8_t *)(_data), \
          |                         ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:453:25: note: (near initialization for 'adv_data[0]')
      453 |                 .data = (const uint8_t *)(_data), \
          |                         ^
    C:/ncs/v2.5.1/zephyr/include/zephyr/bluetooth/bluetooth.h:466:9: note: in expansion of macro 'BT_DATA'
      466 |         BT_DATA(_type, ((uint8_t []) { _bytes }), \
          |         ^~~~~~~
    ../../../src/audio/streamctrl_broadcast_sink.c:504:9: note: in expansion of macro 'BT_DATA_BYTES'
      504 |         BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
          |         ^~~~~~~~~~~~~
    ninja: build stopped: subcommand failed.

  • Hi

    What issues exactly did you have with bt_le_adv_start()?

    It seems what you're trying to input in the .type field of your BT_DATA is not recorded or in the union initializer. This should be the type of advertising data field of your application that isn't set correctly it seems. How have you set the advertising type and UUID type in your project?

    Best regards,

    Simon

Related